MacOS – Why is SSH key different for user@ipaddress vs user@devicename.local (same device)

macosssh

if i ssh into a device (linux) on my local network using user@ipaddress vs user@devicename.local it seems as though my computer (OSX) is treated as two different devices.

I have noticed some inconsistencies with how the firewall on the device (linux) treats my machine and i am just trying to understand the logic

Best Answer

I think you have it backwards - it is not your computer that is treated as two different devices, rather it is the Linux device that is treated as two different devices.

The first time you connect to 111.222.333.444, the SSH (host) key of the Linux device is saved on your computer (usually in the ~/.ssh/known_hosts file). This makes it possible for SSH to check that the key is the same the next time you connect - otherwise you'll get a warning that something is up.

Similarly, the first time you connect to devicename.local, the key is again saved. SSH doesn't know that 111.222.333.444 and devicename.local is actually the same computer, so the key will be saved twice under different names on your computer.

Therefore in the future if you update one key and not the other, you'll experience different behaviour regarding host key warnings when you connect via the IP address or the host name.

Regarding the inconsistencies with your firewall - it is not entirely clear, how you think that is related to your question about the SSH keys being different. In general, a firewall on the server has no way of knowing whether you have opened the connection by typing in the IP address or host name of the server. That information is simply not transferred over the network.

If you observe a difference, it is because the host name does not translate to the same IP address as the one, you're entering manually. This can happen if the server has multiple alias IP addresses, and you're using two of those - or if the server has both an IPv4 address and an IPv6 address, and you're typing one and using a host name that is set to the other.