how to ssh in two machine one after another (in sequence) using shell script
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to ssh in two machine one after another (in sequence) using shell script
I want to know how can i ssh to two machine one inside another using shell script
example
first i have to ssh to the host
then from host i have ssh to a node(say some another host inside first host)
/* some shell script command*/
I have shell script in which i have to ssh to these two hosts one after another run a program and come out of the host
/* some shell script command */
I dont think that is possible just because once you log in the first shell you lose the shell you were just in, but maybe im wrong, curious to find out.
Last edited by david_ross; 09-17-2010 at 09:56 AM.
Reason: removed spam
You should be able to get your remote environment to automatically run execute a command when you log in. Make that command an ssh command and you should be done.
You should be able to get your remote environment to automatically run execute a command when you log in. Make that command an ssh command and you should be done.
I have ssh key but I don't know how to use it
i mean where i have to store in my computer and how?
then how to use it for remote login?
could you please tell me this thing too..
I can't do it
as I login to server(my account) and then every time I have to ssh to my nodes (node0,node1,......) so if i keep a command to ssh to one node then what about the other nodes?
I have a somewhat neater solution for this problem now. I couldn't get it to work properly previously, but had a need to use it myself, so spent some time sorting it out.
Step one: Set up keys on the intermediate machine (call this "server") so that user@server can ssh to the node without needing a password (ie, from account user on server, ssh user@node is passwordless).
Step two: ssh to server forcing pseudo-terminal creation, and passing the final ssh command to ssh
Code:
$ ssh -t user@server ssh user@node
I'd been trying the -t on the second invocation on ssh (ie ssh user@server ssh -t user@node) which doesn't work properly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.