Enabling SSH Access on Mac Using Terminal

Follow these steps to enable SSH access on your Mac entirely via the terminal.

1. Enable Remote Login (SSH)

Run the following command to turn on SSH:

sudo systemsetup -setremotelogin on

Verify SSH is enabled:

sudo systemsetup -getremotelogin

2. Allow SSH Through the macOS Firewall

If your firewall is active, allow SSH connections by executing:

sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /usr/sbin/sshd
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /usr/sbin/sshd

3. Test the SSH Connection

From another machine, try connecting via SSH:

ssh your_username@your_mac_ip_address

Replace your_username and your_mac_ip_address with your actual Mac username and IP address.

Additional

Use Ssh Key for Password-less Auth

Generate a key pair on your local machine (if you don’t already have one):

ssh-keygen -t ed25519

Manually append your public key to the remote’s ~/.ssh/authorized_keys:

# Copy you public ssh key using your custom [copy] alias.
cat ~/.ssh/id_ed25519.pub | copy
 
 
# 1) SSH to your target
# 2) prepare the directory and file
mkdir -p ~/.ssh && chmod 700 ~/.ssh  && touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys
# 3) paste the key into the authorized_keys file (replace the empty string with your copied key from source box)
echo "" >> ~/.ssh/authorized_keys
Link to original