15

I have a virtualbox on which I have installed ubuntu 12.04. My host computer is Mac OS (mavericks). I did a SSH key copy to my remote (which is ubuntu server and I call it myubuntu).

when I did

ssh username@myubuntu
ssh: Could not resolve hostname ubuntuhadoop: nodename nor servname provided, or not known

but when I tried:

ssh username@66.90.115.178

I was able to log in to the remote server (which is myubuntu).

why is it need that I give IP address it connects properply but not the servername.

I am not sure if this is possible. But I found in one of youtube tutorials. ssh myubuntu (NOT username@myubuntu) and logged onto the remote server, without username. is this possible?

brain storm
  • 267
  • 1
  • 3
  • 8
  • 1
    This may give you the solution from the last part of your question: http://askubuntu.com/questions/257472/host-alias-for-ssh – Takkat Jun 24 '14 at 08:38
  • check this answer : https://stackoverflow.com/a/45927052/249697 – Ka. Mar 19 '20 at 12:25

2 Answers2

19

You have a few options.

If you need access from only a few locations, or a single location, update /etc/hosts

sudo nano /etc/hosts

Add an entry for your server

66.90.115.178 myubuntu

Second, purchase or find a free DNS service, http://www.noip.com/free/ or similar.

Third, ssh uses your current user name by default, so if you have the same user name on both client and server, just ssh server_name

ssh your_server

You only need to specify a user name if the names are different or you want a new user

ssh new_user@your_server
Panther
  • 102,067
  • I followed the first option since it is simple now. do I have to restart the computer. right now, it is hanging when I tried ssh myubuntu and I get operation timed out – brain storm Jun 23 '14 at 22:33
  • Not sure about the hang, look at the output of ssh -vvv myubuntu – Panther Jun 23 '14 at 22:35
  • sorry, I had a typo on IP which I found out using ssh -vvv. after I fixed it works great!. one question though, why do you say if you need access from only a few locations or a single location update /etc/hosts. if you could give a line or two for the two methods you described and when they will be useful, they will be helpful for beginner like me. Thank you very much!!!! – brain storm Jun 23 '14 at 22:38
  • Well, it is proportional to how many machines you need to edit /etc/hosts on vs the time it takes to configure a DNS server. – Panther Jun 23 '14 at 22:40
  • There's also an another option for local networks: Avahi (which is installed by default on Ubuntu Desktops). – Andrea Corbellini Oct 20 '14 at 16:14
  • @AndreaCorbellini - I've not had much success with Avahi and I do not think it will work over the internet, not sure ... – Panther Oct 20 '14 at 17:40
  • @bodhi.zazen: that's why I've written "for local networks" ;) – Andrea Corbellini Oct 20 '14 at 19:02
  • I am looking for this answer from last 2 days. thanks buddy – dahiya_boy Apr 05 '20 at 21:01
0

I also had this problem. I had defined another host as below (in /etc/hosts):

hostname1 IP1
hostname2 IP2

I changed it to:

IP1 hostname1
IP2 hostname2
ParisaN
  • 227