Celeb Glow
news | March 10, 2026

PuTTY / plink - How to execute command AND keep shell alive

I'm remote connecting to a linux machine from windows using PLINK and would like to execute some commands in a batch script right after connecting, but it seems I cannot keep the terminal alive.

After reading this little nugget here, I thought that a -t flag would suffice, but that didn't work.

plink my_username@123.456.789.10 -pw my_pass -batch -t "cd /home/app/"
0

2 Answers

Try using KiTTY instead of PuTTY. KiTTY is a fork of PuTTY that - among other features - has a "login script" feature which allows to run certain commands automatically after login (and then keep the terminal open).

If you specify a command on plink commandline, it will ask the SSH server to execute that command and exit. If you want to start shell afterwards, you have to start it explicitly.

If you want to keep using Plink interactively, you probably want to add the -t switch to allocate a pseudo terminal. You will also want the --no-antispoof switch.

plink user@host -pw password --no-antispoof -t "cd /home/app/ && /bin/bash"

A similar question about PuTTY:
How to run a remote command in PuTTY after login & keep the shell running?

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy