0

I'm quite new in this, but i was wondering if there is a way to execute an script that runs the command ssh with another ssh inside the server like this:

ssh <user>@<IP> 'sudo su -; ssh <user>@<IP> 'echo "Hi"''

Or something like that

tink
  • 14,342
  • 4
  • 46
  • 50
Bianca
  • 1
  • 2
    In general, when you want to jump through one host to get to another, that's what `ssh -o ProxyJump firstHost otherHost` is for. – Charles Duffy Oct 01 '21 at 18:48
  • 1
    Beyond that, `sudo su -; anything` doesn't work, because it doesn't run `anything` until **after** `sudo su -` has finished, so you no longer have a process with the escalated privileges `sudo` provides. – Charles Duffy Oct 01 '21 at 18:48
  • 1
    (also, if you're using `sudo` correctly, you never need `sudo su`; `sudo` itself can do everything `su` does, if you use the right command-line options and configuration). – Charles Duffy Oct 01 '21 at 18:50
  • 1
    (and why are you escalating to root just to run a second ssh command? If you need access to a private key, you want that private key to live on the first machine you're starting your connection from, or -- even better -- on a smartcard or YubiKey plugged into that system; it's a Very Bad Idea to have the first host hold a key that gets to the second host, because that means anyone who breaks into the first host can get to the second host without any other authorization). – Charles Duffy Oct 01 '21 at 18:50

0 Answers0