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).
You can create a .reg
file with all the settings:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\SimonTatham\PuTTY\Sessions\MySession]
"HostName"="example.com"
"Colour0"="187,187,187"
...
Import the settings using the reg
command:
reg import MySession.reg
And then load the imported settings using the -load
switch of PuTTY:
putty.exe -load MySession
If you want, you can have the key deleted using the reg delete
after starting PuTTY.
A complete batch file would be:
@echo off
reg import MySession.reg
start putty.exe -load MySession
timeout /t 2
reg delete HKCU\SOFTWARE\SimonTatham\PuTTY\Sessions\mysession /f
(The two-second timeout is there to let the PuTTY load the settings before it gets deleted).
And of course there are loads of PuTTY clones that support configuration INI files. For example KiTTY.
Another option is to make use of WinSCP that can open PuTTY from a session specified on WinSCP command-line:
winscp.exe ssh://martin@example.com/
While WinSCP allows much wider set of options on its command-line, it does not support terminal-specific options, like colors.
(I'm the author of WinSCP)
Best Answer
You need to create a file with two commands, the directory change and the shell start, like:
Then use the command-line parameter
-m
to "execute" the commands. You will also want to use the-t
for force TTY back as the-m
disables it.To avoid a separate command file for each sessions, just generate it from the batch file:
References:
If you want GUI for managing sessions with specific initial remote path, you can use WinSCP.
(I'm the author of WinSCP)