I tried to access one of my mac on a different network using a specified port: 1234
ssh remoteuser@remoteip -p 1234
but I got the result that connection refused
. How do I specify the port I want to use other than the default 22?
macossshterminal
I tried to access one of my mac on a different network using a specified port: 1234
ssh remoteuser@remoteip -p 1234
but I got the result that connection refused
. How do I specify the port I want to use other than the default 22?
Best Answer
From our comment exchange,
it sounds like you did not actually configure
sshd
on your remote Mac to listen on port1234
rather than its default port22
. This is why you're getting a refused connection: Although you may be routing traffic correctly to your remote Mac,sshd
did not open port1234
on that Mac in the first place.You can confirm this by getting onto your remote Mac and either running a port scan (
/System/Library/CoreServices/Applications/Network Utility.app
, Port Scan, address127.0.0.1
, ports1234-1234
) or by trying tossh
locally (ssh -p 1234 user@localhost
).To fix this: You can change your
sshd
port by editing itslaunchd
property list. Note that you will first need to disable System Integrity Protection on macOS 10.11+ and remount your System volume as read/write on macOS 10.15+.