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.
|
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'll let you work out the details. |
you are right I am facing exactly the same problem but I hope someone must know how to do it
|
can you explain me more....
Quote:
|
I'd set up a user, say relay1
In CentOS, I'd edit the user's .bash_profile with a line like Code:
ssh user@target_machine |
I just ran a very quick test and this approach would seem to work
|
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.. |
Read man ssh-keygen
It's not that hard |
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 done the ssh key part now i m able to ssh to server without any password
|
Well my way would be to create a user per node on the server and have a different ssh command in the profile.
|
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 |
Thanks a lot
it's working fine
|
There's a better way to do this:
1. Generate key (with a passphrase) on your workstation using ssh-keygen 2. Start ssh-agent 3. Add key to agent with ssh-add 4. Edit ~/.ssh/config on workstation to add this: PHP Code:
6. Now you can do ssh user@server ssh user@node1 some_command The advantage is that if someone compromises your account on server, they don't automatically get free access to each node. |
All times are GMT -5. The time now is 11:38 AM. |