Ubuntu ssh: Could not resolve hostname myserver: Name or service not known
The problem is, that your local computer do not know myserver. So you have several option:
1.) You can edit your local /etc/hosts and set there the public IP to myserver, but than you need to do it on all computer which should access myserver
2.) If you are own a domain, you can set the public IP of your server to myserver.mydomain.com in your DNS configuration.
3.) You can also set myserver in .ssh/config
Host myserver
Hostname ec2-xxx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com
IdentityFile /Users/TNowak/.ssh/id_rsa
Related videos on Youtube
Rajeev
Updated on June 04, 2022Comments
-
Rajeev almost 2 years
I'm trying login from local machine to aws ubuntu server but I'm unable to login on aws ubuntu server with hostname.
ssh -i key.pem ubuntu@myserver
Getting below error:
ssh: Could not resolve hostname myserver: Name or service not known
I'm able to login with public IP of this server without any issue.
for example:
ssh -i key.pem [email protected]
I have changed the hostname with below commands.
1) sudo vim /etc/hosts
2) 127.0.0.1 localhost myserver
3) sudo hostnamectl set-hostname myserver
used the below link to change hostname.
https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname/
How can login on aws ubuntu server with hostname instead of IP address?
Please help me.
-
Rajeev over 4 yearsHi Thomas, Thank you for reply. I followed the first step now I'm able to login. Thanks again.