Auto start PuTTY from command-line with a specific startup path

I start multiple PuTTY sessions everyday with a specific path in each session.

I have made a command in batch file as

Start "c:\putty.exe" [email protected] -pw abc123 22

How do I proceed further to open PuTTY directly in a specific remote directory.

I have 20 sessions.

Please assist.


You need to create a file with two commands, the directory change and the shell start, like:

cd /path
/bin/bash

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.

putty.exe [email protected] -pw password -t -m commands.txt

To avoid a separate command file for each sessions, just generate it from the batch file:

set SCRIPT_FILE=%TEMP%\commands.txt
echo cd /path > %SCRIPT_FILE%
echo /bin/bash > %SCRIPT_FILE%
putty.exe [email protected] -pw password -t -m %SCRIPT_FILE%

References:

  • PuTTY command-line
  • Starting PuTTY session in a specific directory
  • PuTTY: Run a remote command after login & keep the shell running

If you want GUI for managing sessions with specific initial remote path, you can use WinSCP.

  • WinSCP can work as session manager for PuTTY
  • and it can be configured to open PuTTY in a specific path.

(I'm the author of WinSCP)