Can't SSHing to Ubuntu via hostname and port other than 22

6,491

In Terminal on OS X when using ssh to establish a remote connection using a hostname on a local network, add the suffix .local such that the command reads ssh [email protected] If you need to override the default port 22, as your example of using port 2222, add -p 2222 to the command. You can also set this up in Terminal's "New Remote Connection.." dialog (Command-Shift-K) for easy access.

Share:
6,491

Related videos on Youtube

Blaszard
Author by

Blaszard

Updated on September 18, 2022

Comments

  • Blaszard
    Blaszard over 1 year

    I'm trying to connect to Ubuntu via SSH from OS X, and I took the same step as explained in this page (https://help.ubuntu.com/10.04/serverguide/openssh-server.html). After setting it, I tried to connect by the form of username@ip_address, then it was successful and I was able to be in Ubuntu from OS X Terminal (this time I used port 22). However, when I tried to SSH to Ubuntu by the form of username@hostname, then I couldn't and the error ssh: Could not resolve hostname my_user_name: nodename nor servname provided, or not known occurred. I also tried to connect via port 2222 by changing /etc/ssh/sshd_config, then it failed too by spitting out the error debug1: connect to address my_ip_address port 22: Connection refused (this time I tried to connect by IP address).

    So I think the latter issue stems from the fact that I have to make some sort of modifications also on OS X, but don't know where/how to do and don't know it's true in the first place.

    The former issue is more annoying, as I'm not sure whether I could understand it correctly. I used hostname as the value that I got from running hostname on Ubuntu Terminal...but is it right? And when I searched for the issue on the Web, I knew that it's from DNS issue...but don't know what it is and how to fix it...

    Thanks.

  • Blaszard
    Blaszard almost 11 years
    Thanks for the great explanation. I've been able to run it successfully, both on hostname and port issue. I want to ask one more question... Running ssh username@hostname -p2222 every time when I want to SSH is a bit tiresome... what or how do you (or the community convention) do to cope with the issue? I came up with creating an alias, but is it the best way?
  • Blaszard
    Blaszard almost 11 years
    Thanks. I succeeded by either adding .local suffix as you suggested or modifying /private/etc/hosts Alaa suggested in the above post. Which is the better way? I guess yours is better because IP address changes once I reboot my Ubuntu... but I'm not sure.
  • Alaa Ali
    Alaa Ali almost 11 years
    The problem with using an alias is (I think) you won't be able to specify another port if you wish to connect to another machine. Here's a better way: not sure if it's the same file on Mac, but edit the file /etc/ssh/ssh_config (note, it's ssh_config, not sshd_config) on your Mac and add the line Port 2222 in the end. This will make the default SSH port 2222. However, you can just change back the port to 22 on Ubuntu.
  • Blaszard
    Blaszard almost 11 years
    I found the file in /etc/ssh_config, so I think it is what you pointed to. If I change from port 22 to 2222 in the file, then it means every time I execute ssh command, I always use port 2222 as default...right? And it also means when I try to connect to another machine which doesn't use port 2222, then I have to add -p argument to connect to the specific machine...right?
  • Alaa Ali
    Alaa Ali almost 11 years
    Yes. Also, don't forget to mark an answer as your accepted answer to indicate to others that the question has been solved.
  • Blaszard
    Blaszard almost 11 years
    Yeah, I know I should mark accepted answer but still wonder which is better between yours and douggro's...
  • douggro
    douggro almost 11 years
    With changing IP addresses, the .local option will ensure that you can connect regardless of the machine IP. Even though my server is on a reserved IP, I still use the .local option using the hostname.
  • douggro
    douggro almost 11 years
    @Alaa Yes, the .local directs the connection to the local network for hostname resolution. Works in web browsers too: I connect to my Webmin instance using it.
  • Kenny Evitt
    Kenny Evitt over 9 years
    This doesn't work for me, and it's not terribly surprising as local isn't the name of my (private, internal) domain. Interestingly, I am able to connect to other hosts by hostname via SSH on the same network.
  • douggro
    douggro over 9 years
    @KennyEvitt So, you're running an internal DNS server?
  • Kenny Evitt
    Kenny Evitt over 9 years
    @douggro, yes, effectively; my router provides DNS. What's particularly strange is that both host and nslookup resolve the problematic host.
  • douggro
    douggro over 9 years
    @KennyEvitt I could see the machine not responding to a .local query if there was no mDNS service installed. IS your router hosting a legit BIND zone, or some other host caching scheme?