LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-28-2014, 08:46 PM   #1
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
possible to daisy chain ssh into single command?


I know this may sound a bit silly, but I was playing around with executing a command via ssh and starting trying to ssh from server A into server B and then into C all on a single command?

ex:

Code:
$ ssh userB@serverB 'ssh userC@serverC'
this presented me with the expect p/w prompt for server B, but failed to execute the ssh into server C. I also tried with -t, but that was definitely not what i am looking for.

im not even sure this is doable, so thanks in advance.
 
Old 05-28-2014, 09:03 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

the ProxyCommand directive is good for this. Eg in your ~/.ssh/config
Code:
Host serverC
  User userC
  ProxyCommand ssh -qax serverB /usr/bin/nc %h %p

Host serverB
  User userB
Then from serverA as userA you can get to serverC as userC with the following command:
Code:
ssh serverC
HTH,

Evo2.

PS. If the ssh on serverA is new enough you don't need to use netcat. Instead the ProxyCommand line can be
Code:
ProxyCommand ssh -qax -W %h:%p serverB
Check the ssh man page for the -W option.
 
2 members found this post helpful.
Old 05-28-2014, 09:03 PM   #3
GaWdLy
Member
 
Registered: Feb 2013
Location: San Jose, CA
Distribution: RHEL/CentOS/Fedora
Posts: 457

Rep: Reputation: Disabled
It's doable by bash somewhat, but even moreso by Expect. I don't know of any way to just "daisy-chain" the commands without a script being used, though (I'm far from an expert, though).
 
Old 05-28-2014, 11:55 PM   #4
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Original Poster
Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by evo2 View Post
Hi,

the ProxyCommand directive is good for this. Eg in your ~/.ssh/config
Code:
Host serverC
  User userC
  ProxyCommand ssh -qax serverB /usr/bin/nc %h %p

Host serverB
  User userB
Then from serverA as userA you can get to serverC as userC with the following command:
Code:
ssh serverC
HTH,

Evo2.

PS. If the ssh on serverA is new enough you don't need to use netcat. Instead the ProxyCommand line can be
Code:
ProxyCommand ssh -qax -W %h:%p serverB
Check the ssh man page for the -W option.
now that is some powerful stuff. many thanks. +1 mate.
 
  


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] Single command to run multiple commands on ssh knspradeep Linux - Enterprise 5 10-14-2013 07:40 AM
[SOLVED] Rsync .scp ssh password in single command sanjay87 Linux - Server 3 07-06-2012 01:24 AM
[SOLVED] Bash script: su another user and ssh in the single-command Droa Programming 9 10-13-2011 03:43 AM
Daisy chain two servers -- one with dual ethernet ports angelogladding Linux - Networking 2 12-24-2007 02:07 PM
Daisy-Chain eth0 via cross-over cable? ravenslay3r Debian 2 08-05-2005 03:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:47 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