Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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

ssh -f -L -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

marked as duplicate by Eric Carvalho, Charles Green, Paranoid Panda, AzkerM, David Foerster Dec 2 '15 at 9:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new 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
up vote 19 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
@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

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