You can even restrict certain keys (the passwordless method) to the execution of a single command (in this case, ls) by a proper entry in the authorized_keys file of the host2 user that will run it.
Then you'd just:
ssh -l <user> -i <privatekeyfile> host2
to securely execute the remote command. The advantage here is that the private key, if compromised, won't give shell access to host2.
OpenSSH is useful for a lot of other things, as well. Grab it from
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.