Passing password in script for ssh connection - no except

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing password in script for ssh connection - no except
# 1  
Old 07-22-2011
Passing password in script for ssh connection - no except

Used the script posted on forum - 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 script for ssh connection. Using except is not an option. We have more than 300 servers and need to setup an script to change password. Also setting up ssh public keys for password less communciation is not an option with these limitation, I am using following code, but it just waits on the password prompt. can someone help?
#! /usr/bin/ksh
stty -echo
print -n Enter Old Password-
print -n Enter New Password-
stty echo
exec 4>&1
progdir=$(dirname $0)
for HOST in $( cat "$progdir/.servers" ) ; do
     ssh -T -oPreferredAuthentications=password $HOST >&4 2>&4 |&
     sleep $DELAYprint -p $OLDPASS
     sleep $DELAY
     print -p touch changepassdatafile.$HOST
     sleep $DELAY
     print -p exit


Last edited by radoulov; 07-22-2011 at 05:48 PM.. Reason: Code tags.
# 2  
Old 07-22-2011
Password authentication means password typed by a human authentication. ssh, scp, sftp, su, sudo, and other sane login systems are all designed to require a human at the helm when passwords are involved, and only accept anything else under great duress. This is because storing or passing around plaintext passwords anywhere on your system is an extremely bad idea.

ssh fortunately has secure methods to login without a password. The right files in the right places on client and host allow the login to to through without a prompt. See this article.
# 3  
Old 07-22-2011
I believe current implementation of ssh doesn't allow to pass the password through a switch or automatically. It's for security reasons. You really should use keys.
However, if you for some crazy reason dont want to, I see 2 options:
1. use 'expect' to create the script. While the script si running, anybody can see the password by looking at the running process (e.g. 'ps aux | grep yourScript ')
2. Hack the openssh code.
# 4  
Old 07-22-2011
One work around is to create a key on the local machine. Log into the same account on the local machine through the key. This way you fake a tty through the network connection:
(sleep $DELAY
sleep $DELAY
echo touch changepassdatafile.$HOST
sleep $DELAY
echo exit) |
  ssh -t -t localhost ssh $HOST

# 5  
Old 07-23-2011
Thanks everyone for your replies, yes due to many reasons can not use except and ssh key exchange Smilie.
binlib - will try your solution..

# 6  
Old 07-23-2011
Just curious, why can't you use keys?

binllib's solution might work, but you will echo the password out...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

2. Shell Programming and Scripting

Passing special characters in an SSH connection

I have a script like this #!/bin/bash hello=$1 echo `hostname` $hello ssh gtint16 "echo $hello" if I run this as "hello''", it prints only hello on that ssh session and not the single quotes, but locally its printing hello''. I want the single quotes also to be printed... (2 Replies)
Discussion started by: Tuxidow
2 Replies

3. Shell Programming and Scripting

Passing password with SSH command

Hi Experts, I have specific requirement where I want to pass the password with the ssh username@hostname command . I dont want to use RSA public and private keys also. Because that will be on production server and no one wants to give access like that. Second thing it is production... (14 Replies)
Discussion started by: sharsour
14 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

Password less connection(sftp/ssh)

Dear All, I'm trying to configure a passwordless connection between two servers of HP-UX. i have srearched the configuration in google so many times and as per the guidence i have done all the steps, but still its not working and every time it is asking for password while trying to scp some file... (2 Replies)
Discussion started by: panknil
2 Replies

7. Shell Programming and Scripting

SSH Login by passing password.

ssh/sftp login by passing password , is it possible.Don't want to expect. (1 Reply)
Discussion started by: dinjo_jo
1 Replies

8. Cybersecurity

ssh connection without password

The subject has been outlined in many articles, yet I can not establish a password-less ssh connection. Below I show what I did and then I include ssh debug info, maybe someone would be able to point out something I am not doing right. My setup: two SCO 5.0.7 boxes on a private lan, user... (6 Replies)
Discussion started by: migurus
6 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. Shell Programming and Scripting

passing password in shell script

Hi, Anybody help to write a shell script as below requirement. script stops some costomized application services. 1. first it will stop apache as root 2. then it will switch to my application user and stop app service. Note: passing password is required to stop app service as app... (1 Reply)
Discussion started by: manojbarot1
1 Replies
Login or Register to Ask a Question