Script check if ssh requires a password???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script check if ssh requires a password???
# 1  
Old 02-20-2009
Script check if ssh requires a password???

Thanks to the help from this forum i've learned a lot of good stuff but I still have questions Smilie.
I need to write a script that checks if ssh to a box requires a password. I need it will be an "if" statement, if ssh requires password, then do a key exchange(with i already have). Just need to check if it needs password for ssh. Thanks
# 2  
Old 02-23-2009
Thanks for the kind words.

Please post the script you have written (and don't forget to use code tags).
# 3  
Old 02-23-2009
I have a list of IPs I need to SSH in located in a file called ~/DesktopIPList. When I run this and I don't have a key exchange with a host on the IP list It hangs the script for a few seconds because it can't SSH in.

Code:
remoteuser="root"
for remotehost in `cat ~/Desktop/IPList`
do

### Getting remote hostname ## Just an example command
ssh -q "$remoteuser@$remotehost" hostname

done

The ONLY question is, How can I determine if a host has passwordless SSH access or it requires a password in a script.
# 4  
Old 02-24-2009
I'm not sure if the question is not clear or it's just not possible. Can anyones help? Thanks
# 5  
Old 03-06-2009
I've run into the same problem recently. While I seem to vaguely recall something more useful (along the lines of a --query option for ssh or scp), this should work too.

The option password authentication can be turned off, then you can just mangle the results to fit your need.

Code:
# ssh user@[unauthed_host] -o PasswordAuthentication=no
Permission denied (publickey,password).
# echo $?
255

# ssh user@[unauthed_host] -qo PasswordAuthentication=no echo 0 || echo 1
1
# ssh user@[authed_host]   -qo PasswordAuthentication=no echo 0 || echo 1
0

# 6  
Old 03-06-2009
Thanks for following up... but I when I run that command it still request for a password. Is there any other way I can check if I can do passwordless ssh?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

Script to check the validity of password

Hi, I have to validate the passwords for 100s of unix users across several servers. I have the list of unix users and servers with passwrods. How can I check whether a password is correct or not using a single shell script? Note : I do not have root privileges on any server. All the... (1 Reply)
Discussion started by: Pupil
1 Replies

4. 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

5. 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

6. Shell Programming and Scripting

when i use ssh in my shell script it will promt for a password :(

when i use ssh in my ssh in my shell script it is promt for the password my command is ssh user@server ls -l >log.txt can some one suggest if i am doing wrong. i dont want the script will prompt for a password promt. my requirement is the shell script will take the password inside the... (2 Replies)
Discussion started by: alokjyotibal
2 Replies

7. 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

8. 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

9. Shell Programming and Scripting

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 !#/bin/sh ... ssh -l user remotehost "ls -l" I have shared the public key of the local... (3 Replies)
Discussion started by: farahzaiba
3 Replies

10. UNIX for Advanced & Expert Users

Configured sftp still requires password

Hi Gurus:) I have to connect from a SunOS 5.10 to a 5.8 using sftp in BatchMode. For this, I have generated a Public-Key (ssh-keygen -b 1024 -P "" -t dsa) on the 5.10 and saved it in ~remote-user/.ssh/authorized-keys on the 5.8. Then, running either one of ssh or sftp, it asks for the... (24 Replies)
Discussion started by: unilover
24 Replies
Login or Register to Ask a Question