We have a scenario in which our code is failing to establish ssh connection to an AIX host using public/private key. I took the following approach to perform the troubleshooting,
i. Our code uses JSCH library to establish the SSH connection. To make sure this is not an issue with jsch usage, I made sure the following
1) Public key - Made sure public key is configured in .ssh/authorized_keys file in the target host
2) Private key - Made sure we have the private key and setting it correctly in jsch library
ii. Next step is to see if we are able to connect using ssh tool from a linux machine. Following are the steps
1) Get the private key and create a file named 'privatekey'. Put the content of the private key in the file
2) Now connect to the target machine using ssh -v -i key user@hostname. If it doesn't work, then you can be sure that the problem is not with your code
iii. Next step is to run sshd in debug mode and then try to connect and analyze the debug logs to troubleshoot the issue. Follow the below steps
1) stopsrc -s sshd -> To stop the sshd service
2) /usr/sbin/sshd -D -e -ddd > /tmp/sshd.log 2>&1 - To start the sshd in debug mode. Logs will get written to /tmp/sshd.log
3) Connect to the target host using ssh -v -i key user@hostname
4) Press CTRL + C to stop sshd in debug mode
5) startsrc -s sshd - To start the sshd daemon
iv. Collect the logs and analyze and you should get some clue about what is going wrong
In my case, it is trying to get the public key from authorized_keys2 and as per the my google search this is deprecated log time back in early 2000. Now to figure out from where it is taking authorized_keys2
i. This information is available in the config file /etc/ssh/sshd_config and you need to look for the key "AuthorizedKeysFile". In my case this value is set to authorized_keys2 and after editing this value everything started working
Comments
Post a Comment