LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-12-2012, 12:21 AM   #1
telemeister
Member
 
Registered: Dec 2007
Location: Brisbane Australia
Distribution: Slackware
Posts: 63

Rep: Reputation: 16
SSH config: ProxyCommand for multi-hop ssh


I am doing multi-hop ssh using keys. I am doing an ssh to server2, via server1.
From the command line the following works well:

Code:
 ssh -t www.server1.com  ssh -t www.server2.com
This takes me straight through to server2 without any passwords as expected.

I would like to do the same thing but using the .ssh/config file
The relevant parts of my config file are:

Code:
Host server1
  HostName www.server1.com
  User steve

Host server2
  HostName www.server2.com
  ProxyCommand ssh steve@www.server1.com nc %h %p
  User steve
Now when I try from the command line:
Code:
ssh server1
This takes me onto server1 without passwords
Code:
ssh server2
This takes me to server2. However it is asking me for a password on server2.


Appreciate any clarification as to the correct form of the ProxyCommand (or other switches
in the config file) that will enable the multi-hop ssh to server2, using keys.
 
Old 07-12-2012, 12:40 AM   #2
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
I think you are getting straight to server2 then getting asked for a pass to get on server1. Keys may not be setup hence the password. Maybe the line should read:
Code:
Host server2
  HostName www.server1.com
  ProxyCommand ssh steve@www.server2.com nc %h %p
  User steve
 
Old 07-12-2012, 12:49 AM   #3
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
or...
Code:
Host server1
  HostName www.server1.com

Host server2
ProxyCommand ssh -q server1 nc -q0 www.server2.com %p
 
Old 07-12-2012, 12:52 AM   #4
telemeister
Member
 
Registered: Dec 2007
Location: Brisbane Australia
Distribution: Slackware
Posts: 63

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by micxz View Post
I think you are getting straight to server2 then getting asked for a pass to get on server1. Keys may not be setup hence the password. Maybe the line should read:
Code:
Host server2
  HostName www.server1.com
  ProxyCommand ssh steve@www.server2.com nc %h %p
  User steve
Thanks for the rapid reply..
I tried reversing the servers in the config file as you suggested, but it seems to hang.

I think the keys are OK between all three machines. I can manually ssh without any passwords. Only fails when I use the config file.
Anyway - thanks again for the suggestion.
 
Old 07-12-2012, 12:57 AM   #5
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
May have posted incorrectly on the first one try the or.. post
 
Old 07-12-2012, 01:30 AM   #6
telemeister
Member
 
Registered: Dec 2007
Location: Brisbane Australia
Distribution: Slackware
Posts: 63

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by micxz View Post
May have posted incorrectly on the first one try the or.. post

1. I tried your suggestion of putting the server2 url in the ProxyCommand. I think that might be the same as %h, which substitutes Hostname.
Anyway it does the same as before, except it is now explicitly telling me it is server2 that wants the password. (I get the following prompt)

Code:
steve@server2's password:

2. Re your suggestion of -q0 option in the ProxyCommand: I'm getting

Code:
nc: invalid option -- 'q'
I believe this is coming from the intermediate server (server1)

I've done some checking and server1 is running Fedora, which apparently has a version of netcat which does not support the -q option.
Do you think this -q option is critical to the process?



Thanks again for suggestions.
 
Old 07-12-2012, 02:02 AM   #7
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
the q was just for suppressing errors I don't think it makes a difference in what your trying to do. Does it still fail without the q flags?
 
Old 07-12-2012, 02:15 AM   #8
telemeister
Member
 
Registered: Dec 2007
Location: Brisbane Australia
Distribution: Slackware
Posts: 63

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by micxz View Post
the q was just for suppressing errors I don't think it makes a difference in what your trying to do. Does it still fail without the q flags?
Without the -q option it 'works' ie it does take me through to server 2, but server2 still wants a password, same as before.
 
Old 07-12-2012, 02:35 AM   #9
telemeister
Member
 
Registered: Dec 2007
Location: Brisbane Australia
Distribution: Slackware
Posts: 63

Original Poster
Rep: Reputation: 16
SOLVED: I am going from CLIENT > SERVER1 > SERVER2

When I do it manually ...

Code:
 ssh -t www.server1.com  ssh -t www.server2.com
SERVER2 does not need to know the 'authorised key' for the CLIENT. (i.e. SERVER1 needs to know CLIENT, and SERVER2 needs to know SERVER1)


I seems that when I do it using the .ssh/config file SERVER2 does need to know the authorised key for the CLIENT as well.

I inserted the key from CLIENT into the authorised keys file on SERVER2 and now everything works transparently.

Thanks to micxz for help and suggestions which stimulated the solution.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Multi-hop VNC tunnel over SSH deesto Linux - Networking 6 10-25-2010 07:38 AM
root terminal has different bash config when I ssh in vs su from another ssh account stardotstar Linux - General 4 07-01-2010 06:24 PM
multi hop gateway route thllgo Linux - Networking 4 04-06-2009 01:02 PM
SSH --> Double Hop Howto? kartheekpn Linux - General 16 05-16-2006 02:01 AM
/etc/ssh/ssh.config jeffpoulsen Linux - Software 2 04-24-2003 07:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration