I wish to get logfile from a remotePC via a gatewayServer to my local PC without keying passwords. The gateway server used acctA@gatewayServer. The remote PC used acctB@remotePC.

I have setup the SSH private/public keys on both gateway & remote.

From my local PC, I could SSH into remotePC directly via 2 hops without the need to key the 2 accounts' passwords, using: ssh acctA@gatewayServer -t ssh acctB@remotePC

But when I use SCP with ProxyCommand, it ask me for the password for acctB. Why?

scp -Cp -o "ProxyCommand ssh -q acctA@gateway -W remotePC:22" acctB@remotePC:/opt/logpath/log1.tgz log01.tgz

Advance thanks & appreciation to anyone who can advice.


The easiest thing is to introduce these lines in your .ssh/config file:

  Host remotePC
  User          acctB
  HostName      remotePC
  ProxyCommand  ssh AcctA@gatewayServer nc %h %p 2> /dev/null

which you can then use to connect or copy files simply by means of:

  ssh remotePC
  scp acctB@remotePC:/home/AcctB/somefile .

For this to work, you nee the netcat (nc) command installed on the gatewayServer.

If you really insist on a one-liner (but I can never remember all this stuff), here you go:

ssh -o "ProxyCommand ssh acctA@gatewayServer nc -w 1 %h 22" acctB@remotePC

and likewise for scp.

|improve this answer|||||
  • The .ssh/config is in my local PC or at the gatewayServer? The one-liner didn't work, it still prompt for password. – user1340106 Jun 10 '15 at 1:21
  • It should be on your local machine. Try starting the ssh server, on the remote machine B, as follows: sudo service ssh stop; /usr/bin/sshd -Dd and then try to ssh/scp into it. It will send to the screen all sorts of useful debug info. If in doubt, post it. – MariusMatutiae Jun 10 '15 at 4:17

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.