What the -m
does is, that it makes PuTTY instruct the SSH server to start that command(s) INSTEAD of a shell. So once your command finishes, so does the session.
If you want to run the shell after the cd
command, you need to add it explicitly to your cmd.txt
, like:
cd /my/path ; /bin/bash
Also the -m
implies "nopty"/non-interactive mode. To use an interactive shell you need to override that using the -t
switch.
putty.exe -ssh example.com -m "c:\path\cmd.txt" -t
Alternatively use KiTTY with its -cmd
switch, that does what you want (and does not need a temporary file).
The target server needs to be configured to accept setting environment variables for the 1st option to work. The second is actually working fine, the problem is that it is designed to mimic
ssh user@foo command
which will just connect, run command
and exit. You can have it remain open by giving it command; bash
but that won't work for setting your variables sice a new shell will be started after the variable has been set.
So, short of having root access to the server so that you can enable the setting of environmental variables, the only way I can think of for you to do this is to edit ~/.bashrc
the server and define your PS1
there. Add this line to ~/.bashrc
:
PS1="some stuff"
Now, every time you log into that server, the prompt will be set for you.
Another way to do this would be to use a different rcfile for your bash session. Create a new file with these lines:
source /etc/profile
source ~/.bashrc
PS1='some stuff'
Save it as, for example, ~/.myps1
, then in your putty settings, set the command to run on the remote server to:
bash --rcfile ~/.myps1
This will open a new shell session o the remote server and read in the file above which first reads .bashrc
and then sets PS1
.
Best Answer
For some versions of PuTTY, it's as simple as one of:
If you want to connect using SSH, use this:
For those using Windows, you can simply create a shortcut and pass in these parameters.
For example:
PuTTY - server.com
"C:\Program Files\PuTTY\putty.exe" user@server.com -pw password
If your PuTTY does not support the
pw
parameter, you will need a public key as explained in:Creating and Copying Your Key-Pair in PuTTY SSH Client (alternate up-to-date instruction source).