Saturday 22 September 2018

ssh - Starting PuTTY session in a specific directory


I use PuTTY to connect to a remote server. I want my SSH session to start on a folder that I specify on the server, so I won't have to do cd /my/path/ every time I log in. Possible?



Answer



If you only want the behavior when you log in through PuTTY, you can use "remote command" in the PuTTY configuration dialog (under Connection/SSH). You would type


cd /my/path ; /bin/myshell

into the "remote command" field. If you have more complicated stuff to set up, you would type in the name of a script /home/yourname/yourscript for "remote command" which contains something like


cd /my/path
all-other-stuff-I-need-to-do
/bin/myshell

You need to start the shell manually in your script, otherwise the SSH session will terminate right after your script finishes.


"remote command" has the advantage that you can create different saves sessions in PuTTY where different scripts are called (if you need that).


Of course, if you always want to have the same directory (independent of PuTTY) when you log into your account, you can add the cd command to ~/.profile or ~/.bash_profile as explained by grawity.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...