1

I need to concatenete a cd command with an ssh jump host:

:~$ ssh -tt -C -X user1@server ssh -tt -C -X user2@host "cd ~/my/work/directory ; bash"

but I get the following error:

bash: line 0: cd: /home/user1/my/work/directory: No such file or directory
Connection to host closed.

Seems that ssh try to move to /my/work/directory in the server machine. So I tried to substitue ~/ with the full path /home/user2 but, I get the same error:

Connection to host closed.

In both cases ssh bring me from the client home directory to the server home directory. I also tried to jump host in two different steps (client -> server server -> host) and it works. It seems that the cd step was done in the first ssh (client -> server) instead of the second one (server -> host).

Do you have any suggestion?

1

The first ssh is interpreting this as a list of two separate commands it should run. Your ssh session on server is first executing ssh -tt -C -X user2@host which exits immediately and then running cd ~/my/work/directory ; bash. What you need to do is quote the whole everything from the start of the second ssh to the end of the command so it gets treated as a single thing.

ssh -tt -C -X user1@server 'ssh -tt -C -X user2@host "cd ~/my/work/directory ; bash"'

That way when you ssh into server it will execute ssh -tt -C -X user2@host "cd ~/my/work/directory ; bash" as a whole command instead of breaking it into parts.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.