简体   繁体   中英

Ubuntu ssh: Could not resolve hostname myserver: Name or service not known

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 ubuntu@1.2.3.4

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM