Change mac sshd port
- Open Terminal.app, type
sudo vi /etc/services
, type mac password, then press enter, enter edit mode - Find
ssh
service line, like below:
1ssh 22/udp # SSH Remote Login Protocol
2ssh 22/tcp # SSH Remote Login Protocol
- Modify
22
to the port number you want to change, for example10022
, and save:wq
to exit.
1sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist
2sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
- Now you can login your mac with
10022
port.
Notice
When you change the default ssh port, you need to add -p
parameter to connect the default 22
port.
For example:
ssh root@localhost
will connect to the port 10022
which you DIY.
Change default ssh port
- Open Terminal.app, type
sudo vi /etc/ssh/ssh_config
, type mac password, then press enter, enter edit mode - Find
#Port 22
,remove#
comment, change toPort 22
, save:wq
exit.
Now you can use ssh
command to connect to the default 22
port without -p
parameter.