Sending ssh password in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending ssh password in a script
# 1  
Old 01-30-2009
Sending ssh password in a script

Is there any way to send password in a sh script, to establish a ssh connection with the remote server, without having shared the public key?

The command I'm currently using is in my script is
Code:
!#/bin/sh

...

ssh -l user remotehost "ls -l"

I have shared the public key of the local server with the remote server, therefore I will not be prompted for the password when I execute this script. Is there any way of sending the password in the script itself?

Please do not suggest 'expect' scripts. I do not have expect installed. Am using the default shell that comes along with the server.
# 2  
Old 01-30-2009
Unless you code the script in something like the "expect" program's scripting language the answer is "no".
# 3  
Old 01-30-2009
I installed " Expect" on my Sun box, with help from some guys here on this form, I got the SFTP script working. It works great. You should reconsider and install "Expect".
or you can use Perl. Once again, you need to install Perl.
# 4  
Old 01-30-2009
If you have placed the client's public key on the box being ssh'd too, then there's no need for a password prompt of any kind. However, if the key requires a passphrase, which is prompted for locally, then you do get the idea I suppose of a prompted password. But it's just an "unlock" to use your client private key.

So... I'm guessing that your key has a passphrase associated with it? You may want to consider creating one without a passphrase. Also, ssh is pretty flexible... so if not having a passphrase is disconcerting, you can associate a remote command with the public key so that the desired thing is executed anytime somebody comes across using the passphraseless key.

On a Linux box do a man sshd and search for command= if you want to setup a passphraseless key that does some remote command instead of a shell. When a client has multiple identities you have to specify which key (identity) to use when you do the ssh client call.

Hope that all made sense.... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

1 Script Not Sending Password - Other Scripts OK

I am building FTP Script on my Bluehost VPS Server. I have several and all work great except this one.... I think there are two issues .. One with the command and One with "$" in the password. #!/bin/sh HOST=invtransfer@52.44.151.220 USER=invtransfer PASSWORD=XXX$XXX - $ is real in... (3 Replies)
Discussion started by: Wrjames2
3 Replies

2. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

3. Shell Programming and Scripting

Sending password over SSH

Hi guys, I wrote a script that logs into around 30 nodes via SSH as root. The issue is that I have to punch in the root password everytime and it is being a hassle. Is there a way to save the password in a secure way and automate the whole procedure. I do not want to save the password in... (9 Replies)
Discussion started by: Junaid Subhani
9 Replies

4. Shell Programming and Scripting

Passing password for ssh in Script

I want to do following 2 commands via script: 1) eval `ssh-agent`2) ssh-add /export/home/sufuser/.ssh/id_rsa When asked for passphrase enter "passwordpassword1234 but whenever I run the script it stucks after "ssh-add /export/home/sufuser/.ssh/id_rsa" command and asks fro... (4 Replies)
Discussion started by: yogeshpawar
4 Replies

5. Shell Programming and Scripting

Passing Password to SSH without using expect in a Script

How can I pass password in SSH command without using expect in a shell program. I don't have expect installed on my Solaris server. #!/bin/bash ssh user@hotname (how to supply pass in script?:wall:) Experts please help its very urgent. Shrawan Kumar Sahu (4 Replies)
Discussion started by: ss135r
4 Replies

6. Shell Programming and Scripting

Passing password in script for ssh connection - no except

Used the script posted on forum - unix.com/shell-programming-scripting/21597-script-change-passwords-same-user-multiple-servers.html but the last question posted on this seems to be still unanswered, tried different things with no success, can someone help giving an way to pass the password via... (5 Replies)
Discussion started by: sapadmin
5 Replies

7. Shell Programming and Scripting

Expect Script sending password with $ and symbols

All, I am trying to use expect to send SFTP password because I am unable to share a key with the vendor. They gave me a password that uses some symbols in it like $ and ! When i try to use the send command in expect it thinks the $ is a variable. Is there anyway to have it send the... (2 Replies)
Discussion started by: markdjones82
2 Replies

8. Shell Programming and Scripting

ssh password script

ssh -L 9111:185.222.135.157:9222 -l xxmasrawy localhost i use this command to open tunnling between server and local host the return asked me for password i want to put this command in script and take password from script what can i do (2 Replies)
Discussion started by: xxmasrawy
2 Replies

9. Shell Programming and Scripting

ssh - passing password in shell script

I have a requirement, I need to run a command at remote system using a ssh. Is there any way we can pass the username and password in shell script to the ssh command as we did it in one of the shell script for FTP. ftp -n $i <<!EOF >> user Username $PASSWD cd /home/scripts ... (5 Replies)
Discussion started by: Muktesh
5 Replies

10. Windows & DOS: Issues & Discussions

ssh: sending password from windows client

Hi. My workstation is Windows. I use putty to connect to unix servers. The problem is that i'm doing it many times a day and each time i need to supply password. I have no control on ssh configuration on servers, because of account restrictions. So i can't use key authentication, how is suggested... (4 Replies)
Discussion started by: kukuruku
4 Replies
Login or Register to Ask a Question