Environment: Ubuntu 14.04.
When I use no-root account for ssh multi-hops, it's OK.
But when I switch to root account (by $sudo -i
), the ssh multi-hops doesn't work and it always gives error "bash: nc: command not found
", and /bin/nc is surely there!
Very strange. Anybody has some hints?
The multi-hops ssh config is something like this:
cat ~/.ssh/config
# Multi-Hop SSH
Host serverA
HostName serverA.abc.net
# Multi-Hop SSH
Host sha
ProxyCommand ssh -q serverA nc sha.abc.net 22
It's difficult to tell precisely what your problem is from this distance, but it's possible it has something to do with your path being unset, or set in correctly, in your shell environment on "serverA".
My initial suggestion, which I suggest you do not use, is to specify nc
's location with its full path. Thus:
ProxyCommand ssh -q serverA /bin/nc sha.example.net 22
Just remember for the sake of portability that nc
may not live in this location on all systems. For example, it's at /usr/bin/nc
on FreeBSD and OSX.
I don't recall what version of OpenSSH is included with Ubuntu 14.04, but if it's recent enough (i.e. OpenSSH version 5.4 or later), you could replace the nc
command with SSH's internal -W
option, which instructs ssh to run in "netcat mode". I would replace your ~/.ssh/config
entries with the following:
# gateway host
host serverA
hostname serverA.example.net
host sha
proxycommand ssh -xaqW%h:22 serverA
Note that I'm also including -x
and -a
to disable forwarding of X11 and agent authentication.
As for your query about doing this as root, I would suggest that you DO NOT use ssh as root. Either on the server or the client. Confirm that PermitRootLogin no
is set in your sshd_config file (in /etc/ or /etc/ssh/), and only ever authenticate as unprivileged users. On the client site, build your automation into unprivileged users who, if they need access to certain root accounts on the remote system, get that access using sudo. It's never a bad idea to do things the Right Way. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With