0

I try to alias to multi-hop SSHing and to put some additional commands to this alias after login to the remote machine. I have already working alias to ssh-ing to remote machine

alias comandname='ssh -t -t -X '\''login@machine1'\'' exec "ssh -X '\''login@machine2'\''"'

but I don't how to put command to run on the machine2. I also tried to put something into .bashrc on machine2 (it didn't work) but I would like to know more general solution to have several different command under different aliases. The simple example command would be cd to specific folder on machine 2 from this alias.

2

I've had more success with adding configuration stanza's to $HOME/.ssh/config

eg.

Host machine2-via-machine1
    ProxyCommand ssh -q machine1 -W machine2:22

then you should be able to

ssh machine2-via-machine1

instead of an shell alias.

Since ssh no understands the multihop arrangement ; additional arguments on the command line are processed you might and host key validation seems to be better too.

  • 1
    Use -W switch to ssh instead of nc. – Jakuje Jul 13 '17 at 10:10
  • @Jakuje That is better. I've edited my answer to include your suggestion thanks. – rgammans Aug 7 '17 at 22:07

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.