Handling ssh permission denied or timeout


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Handling ssh permission denied or timeout
# 1  
Old 04-02-2015
Handling ssh permission denied or timeout

Hello all,

been writing a little inventory script (hpux 11.23, ksh Version 11/16/88) which takes our hostname from our inventory db and tests them with ssh connection.

I need to be able to differentiate a timeout (host not reachable on main net link could try adm prod back links) and a permission denied (which would basicly be a bad key).

Thing is the return code can't help me. Anybody has a tip on how i would be able to handle such case?

Code:
[username@checkinghost]/var/opt/username> ssh -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -o "ConnectTimeout=3" host1
ssh: connect to host host1 port 22: Connection timed out
[username@checkinghost]/var/opt/username> echo $?
255

Code:
[username@checkinghost]/var/opt/username> ssh -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -o "ConnectTimeout=3" host2
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
[username@checkinghost]/var/opt/username> echo $?
255

The only lead i've tried is redirecting the standard error into standard output and greping both error message. Works on the command line but i wonder how it would fare into a script. There must be a simpler way.

Thank you for your help!
# 2  
Old 04-02-2015
The reason it doesn't give exit status for this is because it's supposed to give you the exit status of whatever happened on the remote end. This makes it hard to tell the difference between the code ssh gave you, and the code the remote host (if any) gave you.

The same is true for error output actually, since something on the other end could conceivably print that message on stderr instead of the local program.

Try ssh ... -E logfile instead of ssh ... 2>logfile. This definitively separates errors ssh prints from things that happen on the remote end.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-02-2015
I understand now. Yes this will be harder than i tought.

The -E looked like a promising lane until....

Code:
ssh: illegal option -- E

Code:
man ssh
HP-UX Secure Shell is based on OpenSSH version 5.9p1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Permission denied

Trying to get date into the txt file. It says Permission denied. echo $(date +%I:%M:%S_%D) >> /tmp/systemd_suspend_test_err.txt exec 2>> /tmp/systemd_suspend_test_err.txt if ; then # Do the thing you want before suspend here echo "we are suspending $(date +%I:%M:%S_%D)." elif ;... (5 Replies)
Discussion started by: drew77
5 Replies

2. OS X (Apple)

"Permission denied" when trying to SSH my iPhone though password is correct

Hi, I hope this is the correct section in the forum to post as I'm trying to SSH from my MacBook. I was looking to see whether ssh on my jailbroken iPhone 6s (10.3.1) still works fine and was following this old reddit guide. I installed OpenSSH&OpenSSL from Cydia and changed the password using... (7 Replies)
Discussion started by: hss1
7 Replies

3. AIX

SSH connection "Permission denied"

Hello, I tried to connect with root or any other user to AIX using ssh. It throws me error like Permission denied (publickey,keyboard-interactive). i don't know why!! and the PermitRootLogin is yes any help will be appreciated Thanks (7 Replies)
Discussion started by: moudmm
7 Replies

4. AIX

ssh permission denied

Hi Admins, I am not able to login AIX 5.3 server using ssh recieving below error # ssh 10,.10.101.10 ksh: ssh: 0403-006 Execute permission denied. below is sshd_config file # $OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $ # This is the sshd server... (4 Replies)
Discussion started by: newaix
4 Replies

5. AIX

SSH Error - Permission denied (publickey,keyboard-interactive)

Hello, I'm trying to setup password less authentication to remote ssh server. I generated the public key and gave it to the vendor and The key is added in the remote machines authorized_keys file. When I try to connect to a remote machine through SFTP username@host I am getting the error... (4 Replies)
Discussion started by: nice_chapp
4 Replies

6. Red Hat

Permission denied

Hi guys im new to this db i have a small prob while installing websphereportal6.1i think i was installed succesfully but the error im getting is while starting server. check this out # ./serverStatus.sh -all Error loading: /usr/wps61/AppServer/java/jre/bin/classic/libjvm.so: cannot... (1 Reply)
Discussion started by: varma917989
1 Replies

7. AIX

ssh permission denied

I get the following message when running ssh (with password authentication off) - Permission denied (publickey,password,keyboard-interactive). File permissions appear to be fine (700 for .ssh and 600 for files within it) any ideas or clues would be appreciated. (3 Replies)
Discussion started by: gefa
3 Replies

8. UNIX for Dummies Questions & Answers

Why do I keep getting .:Permission denied?

I'll start off by saying that I know very little about Unix - however, I do know that I have a .profile file in my home directory, and that I should be able to invoke it by typing . profile. However, when I do this for ANY .filename, I get ".: Permission denied". I'm pretty sure that there is... (12 Replies)
Discussion started by: bbersani
12 Replies

9. UNIX for Dummies Questions & Answers

SSH permission denied (publickey)

Connecting to -> Ubuntu server running apache Connecting from -> Mac OS X 10.4 As soon as I had created my 'dsa' and 'rsa' keys I sent them to be added to the 'authenticated whatever file' so I could connect. The first time I tried it... Asked for pasphrase Connected to server no prob ... (2 Replies)
Discussion started by: VRoemer
2 Replies

10. UNIX for Dummies Questions & Answers

permission denied??

i'm trying to set up my internet connection and i was told i need to edit the file /etc/ppp/pap-secrets but i get a permission denied message...why?? (6 Replies)
Discussion started by: justchillin
6 Replies
Login or Register to Ask a Question