2

$ ssh -o User=fred -o ProxyCommand="nc -X 5 -x localhost:9150 %h %p" server.example.org

It's from http://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts

I can't find any comments about the %h and %p arguments.

4

It's in the manpage, under the section for ProxyCommand:

Specifies the command to use to connect to the server. The command string extends to the end of the line, and is executed with the user's shell. In the command string, any occurrence of ‘%h’ will be substituted by the host name to connect, ‘%p’ by the port, and ‘%r’ by the remote user name.

So in this case, %h will stand for server.example.org and %p will stand for 22.

By the way, an easier way to spell -o User=fred is -l fred.

  • Thanks. What if I omit the %h and %p here? What would happen? Since the ssh itself has the -P argument already. – AGamePlayer Feb 10 '15 at 8:19
  • Well, if you omit the %h and %p then the nc command no longer makes sense because nc is expecting arguments there. So nc should give you an error. – Celada Feb 10 '15 at 8:25
  • Still not quite sure the %p meaning. For instance: ssh -o ProxyCommand="nc -X 5 -x localhost:8888 %h %p" -P 61234 so for this command, the -P 61234 specifies the port to be 61234 and what does %p mean then? – AGamePlayer Feb 10 '15 at 8:28
  • If you have -P 61234 on the command line (or in a config file) then 61234 will be substituted for %p in the ProxyCommand, same as server.example.org gets substituted for %h. And if you had a %r in there then it would stand for fred. – Celada Feb 10 '15 at 8:32
  • @AwQiruiGuo The -P is for ssh and the %p is for nc. They both need to know the port. – casey Feb 10 '15 at 13:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.