I'm trying to make a bash that SSH's into one server and SSH into another once in, and execute commands on my second server and exit both of them after.

so far I got

ssh [email protected] "ssh [email protected]; cd Dirk; source venv/bin/activate; python app.py; exit; exit;"

but it seems that I can't execute commands for the second server I ssh'ed into from the first. How would I do this?

2 Answers 2


When you run just ssh user@host without a command given as an argument, as in your nested call, ssh will start a shell and wait for commands to be typed in.

Piping commands into ssh host1 ssh host 2 should work. To use the same example as in your question:

echo "cd Dirk; source venv/bin/activate; python app.py" \
| ssh [email protected] ssh [email protected]

ssh -t is maybe your solution

ssh [email protected] -t "ssh [email protected] -t 'cd Dirk; source venv/bin/activate; python app.py; exit; exit;'"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .