Unable to do ssh into machine.

Unable to do ssh into machine.
4.9 (98%) 10 votes

Unable to do ssh

Unable to do ssh into machine? I have seen this problem many time and i know this is one of the problems that everyone faces. Below are my personal list of things that you can try to solve this problem.

Check for key permissions.

This happens if you key or pem file does not have the correct permissions. The correct permission is suppose to be 400. Use the below command to fix it.

sudo chmod 400 keyfilename.pem

Agent is not initialized. 

Run the below command to initialize your ssh-agent.

ssh-agent

Keys are not added to the agent.

Sometime the ssh-agent does not have the keys added to it. This happens when you have generated a new key. Run the below command to add all the keys to the agent

ssh-add

Check if you server is running and ssh port is reachable.

You can use below command to check this

telnet ip_of_server 22

If it is able to connect this means your server is running and the problem is somewhere else. If not this is the problem, your server may not be running of your network is not allowing it on port 22.

Verify for DNS

If you are using DNS to ssh. Verify if the DNS resolution is working fine. To do this run the below command.

dig domain_name_of_server

If you get the answer section in response like below then it is working

$ dig google.com

; <<>> DiG 9.8.3-P1 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47141
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com. IN A

;; ANSWER SECTION:
google.com. 299 IN A 172.217.163.206

;; Query time: 58 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Sun Jun 3 00:27:47 2018
;; MSG SIZE rcvd: 44

Else this could be a problem and your DNS resolution is not working properly.

Going into verbose mode

Run the ssh command in verbose mode and see what all are you getting in logs. These logs will cover all the above problem and will tell you weather you are able to reach the server or not, if there is any key problem and you are authenticated or not. To do this run the below command.

ssh ip -vvv

this vvv increase the verbose level to max and you can see all the logs of the things it tries to attempt.

If you are getting no more keys to try or something like this in the logs. It means your key is not present on the server.

These were the few steps that you can take to resolve your issues. Please mention the steps that you can take to resolve these issues.
If you like the article please share and subscribe.

 


Gaurav Yadav

Gaurav is a Full Stack Web Developer and Blogger. Sportsperson by heart and loves football. He has experience with various frameworks in php, python and javascript. Loves to explore new frameworks and evolve with the trending technology.

Leave a Reply

Your email address will not be published. Required fields are marked *