70

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?

Lucio
  • 19,191
  • 32
  • 112
  • 191
Baruch
  • 812

1 Answers1

106

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.

Eliah Kagan
  • 119,640