ssh in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh in shell script
# 8  
Old 12-10-2009
Setting up keys for passwordless authentication isn't rocket science. On the machine you want to connect from run
Code:
ssh-keygen -t dsa < /dev/null

That will create a private and a public key called ~/.ssh/id_dsa and id_dsa.pub. Now, copy the contents of id_dsa.pub into the file ~/.ssh/authorized_keys2 on the machine you want to connect to, eg
Code:
cat ~/.ssh/id_dsa.pub | ssh user@remote 'mkdir -p .ssh; cat >> .ssh/authorized_keys2'

If you connect afterward, you shouldn't be promped for a password. If you try to connect from a machine that hasn't got the private key, you'll still be asked for a password.

IMHO, it's more secure than passwords in scripts. They're impossible to guess, easy to revoke (just remove the entry from the authorized_keys2 file), and you can even tie access to a specific user on a specific machine (just allow only that one unique key). if you're uncomfortable with the procedure, experiment on some non-critical machines first (eg. some development machines or VMs)
# 9  
Old 12-11-2009
maybe something like this?

Code:
#!/usr/bin/expect
set timeout 20
spawn  ssh [server-ip]
expect "[something from the login prompt]"
send "[username]\r"
expect "[something from the passwd prompt]"
send "[passwd]\r"


Last edited by pludi; 12-11-2009 at 04:42 PM.. Reason: code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

SSH on a Shell Script

Hello, I'm sure you'd have received a lot of questions like this, but I couldn't find anything relevant to my problem in the first search. Sorry in advance if this is a repeated question. I'm trying to do an SSH inside a shell script and expect the shell script to connect to a remote server... (6 Replies)
Discussion started by: mathbalaji
6 Replies

2. UNIX for Advanced & Expert Users

SSH using shell script terminates the script execution

Hello, I am writing a shell script in which i do ssh to remote server and count the number of files there and then exit. After the exit the shell script terminates which i believe is expected behavior. Can some one suggest me a way where even after the exit the script execution resumes. ... (2 Replies)
Discussion started by: manaankit
2 Replies

3. Shell Programming and Scripting

Shell Script with ssh command

How do I use the ssh command to connect to another server without the password prompt? I use: ssh user@host and it prompts for the password. how do I include the password in the ssh command? alternatively, how do you execute 1 command from server A on server B? thanks, ... (4 Replies)
Discussion started by: toughlittleone
4 Replies

4. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

5. Shell Programming and Scripting

SSH shell script does not work

Hello I have a Zabbix Server were Linux kernel version 2.6.26-2-amd64 is running. now my Question how can i make a script that does: - connect with ssh to a device - get the systeminfo (but only the interfaces, mac adresses, serialnumber and Software version) - write the output in a file ... (18 Replies)
Discussion started by: Fraggy
18 Replies

6. Shell Programming and Scripting

shell script to ssh a file

hi all, needed some help writing a script (preferably in ksh) which : 1) detects if a file with ext '.kbs' has been changed. This file always sits in a particular dir. 2) if file has been changed then scp that file from one serverA to another serverB. so far i have not done any... (2 Replies)
Discussion started by: cesarNZ
2 Replies

7. Shell Programming and Scripting

Help with ssh command in shell script

Hi All, I am using ssh in my shell script. Can any one please suggest me option so that i can avoid the login message as below in the execution: NOTE: Please note that you have logged into the newer version of server "gabbro" ******* Performing functions to this computer withe the... (6 Replies)
Discussion started by: vikash_k
6 Replies

8. Shell Programming and Scripting

ssh using shell script

I need to ssh a server using shell script and run certain commands there. Please let me know how to do it . Thanks! (4 Replies)
Discussion started by: asth
4 Replies

9. Shell Programming and Scripting

ssh into a shell script (KSH)

Hi all, Just like to ask if it is possible to do the following: 1. Have a shell script that calls ssh username@destinationhost 2. Upon successful verification, we ssh into the destination host and automatically use ksh to run a shell script that resides in the destination host. (Hopefully no... (8 Replies)
Discussion started by: rockysfr
8 Replies

10. UNIX for Dummies Questions & Answers

Problem with SU or SSH in shell script

Hi Floks! This is Sravan! I am new to linux and I am trying to write bash shell script in which I want to change the user but the statements which are after the "su " command are not working that I mean I want to execute some statements as the changed user here is the code ... (2 Replies)
Discussion started by: sravanp
2 Replies
Login or Register to Ask a Question