0

I want to connect my iMac remotely via ssh. Even though I can connect it locally, I can't do it remotely. When I try to connect remotely it refuses the connection.

port 22: Connection refused

I saw lots of discussions about the problem but w/o success. This is why I am opening a new thread.

I also disabled the firewall but still cannot connect. For diagnosing purposes, I executed netstat tupan and I see ssh local address as 192.168.1.33.ssh and Foreign address as 192.168.1.33.49883. Here is the output.

Proto Recv-Q Send-Q Local Address Foreign Address (state)

tcp4 0 0 192.168.1.33.ssh 192.168.1.33.49886 ESTABLISHED

tcp4 0 0 192.168.1.33.49886 192.168.1.33.ssh ESTABLISHED

tcp4 0 0 192.168.1.33.ssh 192.168.1.33.49884 ESTABLISHED

tcp4 0 0 192.168.1.33.49884 192.168.1.33.ssh ESTABLISHED

Could someone explain me what does this mean? Are those 49884 and 49886 are port numbers? Should I open new ports via port forwarding? And most importantly, could you guys explain me how can I connect remotely via ssh in layman terms please?

B.R.

4
  • Which command did you type to get: port 22: Connection refused?
    – dan
    Feb 17, 2019 at 18:01
  • Does the iMac you want to reach have a public IP address? Can you test it from your remote location with ‘ping my_iMac_IP_address`?
    – dan
    Feb 17, 2019 at 18:07
  • For the first question: ssh command . And for the second: no, I do not have static IP address. What I do is checking my dynamic ip from a website like whatismyip.org . Feb 18, 2019 at 12:33
  • [bis] Can you test it from your remote location with ‘ping my_iMac_IP_address`?
    – dan
    Feb 18, 2019 at 14:22

1 Answer 1

5

Yes, the numbers 49884 and 49886 you see are indeed port numbers. However, they're not port numbers for the ssh service itself, but are the port numbers these specific clients have used for connecting. The numbers are essentially meaningless for you.

The usual problem that home users have with connecting remotely over SSH to their own computer is that their network is behind a NAT (Network Address Translation) router. Essentially this means that your router has a single public IP address, but allows multiple devices behind it to connect to the internet even though they have private IP addresses that are not "visible" on the internet.

The most common way to enable remote access over SSH is to add a port forward in the router. You'll need to port forward your remote IP port 22 to port 22 on the local IP of your iMac. How that is done depends on the exact router you have, but is usually explained in the manual or web interface help.

6
  • So you mean the port 22 is not open in router by default? Feb 18, 2019 at 12:32
  • I have a question about the second paragraph, I do not have static IP but when I check my IP address from whatismyip.org I see an IP. But at the same time in the local network I have another IP address for the iMac. I think you meant that, right? Feb 18, 2019 at 12:40
  • 1
    No, routers do not usually come with a standard forward for port 22.
    – jksoegaard
    Feb 18, 2019 at 13:26
  • 1
    @KadirGunel whatismyip.org doesn't give you your iMac IP address (which is a private one), but the public IP address of your router. Don't confuse public / private and static / dynamic.
    – dan
    Feb 18, 2019 at 14:28
  • 1
    More specifically: when you SSH in remotely, you are attempting to connect to your router - which is refusing the connection. You need to tell your router to forward any incoming SSH connections to your iMac. Perhaps pick a nonstandard port (i.e. forward external port #### to internal your.iMac.ip:22) to reduce drive by login attempts. Not perfect but better than leaving 22 open. Even better, route login attempts on 22 to a blacklist.
    – dr.nixon
    Feb 18, 2019 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .