Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need to run the following command (with real parameters) after login:

ssh -f user@example.com -L 54321:example.com:54321 -N

I need it only for my user, not all users on the machine. Also, I need it to run whether I login via the GUI or via SSH to a plain shell terminal. I would even like to know how to do this on machines without a GUI installed.

Where would I put the above line to be run as explained?

share|improve this question
    
Have you looked at this post? Also, see How to run scripts on start up? –  Lucio Mar 19 '13 at 18:07
    
@Lucio That doesn't address how to make it run for both graphical and non-graphical logins. –  Eliah Kagan Mar 19 '13 at 18:08
    
@EliahKagan Yes, I know that. I'm still looking other post, but those link will be useful to login via GUI. –  Lucio Mar 19 '13 at 18:09
    
@Lucio I found plenty of explanations how to do it for GUI or for shell or for all users. None of those are what I need. –  baruch Mar 19 '13 at 18:11

1 Answer 1

up vote 5 down vote accepted

Adding the command to the end of ~/.profile should do the trick (where ~ represents your home directory).

Not ~/.bashrc, which would make it run again every time a bash shell is started. In contrast, .profile is only run by interactive login shells. See man bash and man sh for more information.

Please note that this will run not just for GUI and SSH logins, but for all logins (or at least all interactive logins), including when you log on in a virtual console.

share|improve this answer
    
It could work using ~/.bash_profile? –  Lucio Mar 19 '13 at 18:15
2  
@Lucio If .bash_profile exists, then it overrides .profile for bash. I don't think the GUI uses a bash shell, though. I'll edit this to provide a link to man sh too (though I'm not sure it uses sh/dash either). .profile is universal (and typically, when .bash_profile exists, it's written so it sources .profile). –  Eliah Kagan Mar 19 '13 at 18:17
    
Great answer. If you want to find more information you can look this SO post. –  Lucio Mar 19 '13 at 18:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.