SSH to a server and exit out


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH to a server and exit out
# 1  
Old 09-29-2006
SSH to a server and exit out

Hi,
Can someone please help me in resolving this issue -

I am doing SSH from a server 1 to another server 2 and executing some statements there and then automatically exit out of second server to the first where script was getting executed.

Can you please help me script this code ?

Thanks
# 2  
Old 09-29-2006
From a script on server1, you can run "ssh [user]@server2 [command]" and whatever is in [command] will execute on server2 as user [user].

You will be prompted for a password unless you set up public keys, which basically involves:
(Presume user running script on server1 is "fred" and logs in as "bob" on server2 to run commands listed in fred's script on server1.)
Run "ssh-keygen -t dsa" as whatever user uid the script will run from on server1 (fred). Press [enter] when prompted for passphrase (twice).
Copy ~fred/.ssh/.id_dsa.pub to ~bob/.shh/authorized_keys on server2.

Run "ssh server2 date" from fred's shell on server1 to confirm that you can log in as bob on server2 via ssh without a password. The first time you might have to reply with "yes" so that's another reason to test manually first.

If login fails (if it asks for a password) you might have to change permissions on ~bob/.ssh* on server2 to whatever the sshd server requires. Checks logs to confirm this.
# 3  
Old 09-29-2006
Thank you sir,

It really helps a lot.
Appreciate you valuable time.

Regards
# 4  
Old 09-29-2006
Quote:
Originally Posted by rajpuneyani
Thank you sir,

It really helps a lot.
Appreciate you valuable time.

Regards

I think remsh perform the remote execution better than ssh.

remsh <servername> -n <command>
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to test for the ssh exit status in script?

Hello; I regularly run monitoring scripts over ssh to monitoring scripts But whenever a server is hung or in maintenance mode, my script hangs.. Are there anyways to trap exit status and be on my way ?? Looked at the ssh manpage and all I can see is a "-q" option for quiet mode .. Thank... (2 Replies)
Discussion started by: delphys
2 Replies

2. Shell Programming and Scripting

how to exit ssh session

Hi , I am running a script on multiple servers.When I run that script on one server,I want to exit from that server and want to go to next server.PFB script: Suppose there are 3 servers:server1,server2,server3.I am currently in server1. for h in {2..3} do ssh username@server$h <<EOF ... (4 Replies)
Discussion started by: sonu141
4 Replies

3. Shell Programming and Scripting

ssh hangs on exit

Hi, Any workaround for this issue, since i am using one script to execute the remote script for several remote server, everything works fine except some of the servers process are hangs even its completed. ---Please help me to resolve this issue---- Script details are here.. Code:... (0 Replies)
Discussion started by: l_gshankar24
0 Replies

4. Shell Programming and Scripting

ssh hangs on exit

Hi, Any workaround for this issue, since i am using one script to execute the remote script for several remote server, everything works fine except some of the servers process are hangs even its completed. ---Please help me to resolve this issue---- Script details are here.. for... (2 Replies)
Discussion started by: l_gshankar24
2 Replies

5. Shell Programming and Scripting

expect ssh script cannot finish and exit

All i am new to linux, and try to have a simple expect script to ssh then telnet to the network equipment, and exit itself. but dont know why i hang at the last $ #!/usr/bin/expect set timeout 10 set arg set arg1 spawn ssh -l UserA 1.1.1.1 expect "assword:"; send "PasSwOrD\r";... (1 Reply)
Discussion started by: samoptimus
1 Replies

6. Shell Programming and Scripting

Need help on how to exit a script run on a server from a remote server

hi, I am using the below line to run a script from remote server(say server A) to another server(say server B). ssh username@servername ksh script name. The issue is the script logs into server B, executes the script on server B, transfers the file to server A but does not exit from... (4 Replies)
Discussion started by: yohasini
4 Replies

7. Shell Programming and Scripting

Exit SSH if it is interactive

I am writing an automation that will ssh into hundreds of system and run a few commands. I ll be looping from ip X.X.X.10 to X.X.X.200 I have public key set up ready for "most" of them to run ssh non interactively. However some of the systems in these ip range do not have the public private key... (2 Replies)
Discussion started by: vickylife
2 Replies

8. UNIX for Advanced & Expert Users

Multiple ssh, shutdown and exit script

PROBLEM: I need to ssh into multiple remote machines, send a shutdown command and exit. The remote servers will then run their own scripts to gracefully shutdown their applications before shutting down. ONE: This is to be achieved without using public key authentication; this is being avoided... (2 Replies)
Discussion started by: ulemsee
2 Replies

9. UNIX for Advanced & Expert Users

How to exit ssh

Hi, I have a script that runs ssh to multiple systems. It does the folowing : ssh -f -T server1 "/sbin/init.d/logsurfer newstart" Running it using the -f option at least the prompt gets back, running it without the -f the prompt does not even show up. You have to press <Ctrl> + c to get the... (1 Reply)
Discussion started by: davidg
1 Replies
Login or Register to Ask a Question