keepcalculator

06 Numbers and Powers

Enable SSH on Mac: Terminal Command

Card No. 06·86227 · Updated · Standard formula, shown below

To enable SSH on a Mac from the command line, open Terminal and run sudo systemsetup -setremotelogin on. This turns on the built-in SSH server (sshd) and allows incoming SSH connections using your macOS username and password.

What SSH Is and Why You’d Use It

SSH (Secure Shell) is a network protocol that lets you securely connect to another computer over an unsecured network. On a Mac, enabling SSH means you can log in from another device—another Mac, a Windows PC, a Linux machine, or even a phone—and run commands as if you were sitting in front of it. Common uses include remote administration, transferring files with SCP or SFTP, and tunneling other protocols (like VNC or web traffic) through an encrypted connection.

The SSH server on macOS is OpenSSH, the same software used on most Linux systems. It’s installed by default but disabled. When you turn it on, macOS starts the sshd daemon, which listens on TCP port 22 for incoming connections. The service is managed by launchd, so it starts automatically at boot and stays running until you turn it off.

Prerequisites and What You Need

  • macOS version: Any recent version (macOS 10.14 or later) has the same command. Older versions also work, but the exact menu path in System Settings may differ.
  • Administrator privileges: You need an admin account to run sudo. The command will prompt for your password.
  • Network access: The Mac must be reachable on your network. For remote access over the internet, you’ll need port forwarding on your router or a VPN.
  • Firewall: If macOS’s built-in firewall is on, it will automatically allow incoming SSH connections once you enable Remote Login. But third-party firewalls may block port 22.

How to Enable SSH via the Command Line

Open Terminal (found in Applications > Utilities). Then run:

  1. Type sudo systemsetup -setremotelogin on and press Return.
  2. Enter your administrator password when prompted. You won’t see characters as you type—that’s normal.
  3. Wait a few seconds. The command returns no output on success.

To verify it’s running, use sudo systemsetup -getremotelogin—it should print Remote Login: On. You can also check the listening port with sudo lsof -iTCP -sTCP:LISTEN -P | grep sshd.

If you prefer the GUI, go to System Settings > General > Sharing and toggle on Remote Login. That does the exact same thing as the command.

How to Disable SSH

To turn it off, run sudo systemsetup -setremotelogin off. This stops the sshd daemon and blocks incoming connections. If you only need SSH temporarily, it’s good practice to disable it when not in use to reduce exposure.

Connecting to Your Mac After Enabling

From another computer, use the command ssh username@mac-ip-address. Replace username with your macOS username and mac-ip-address with the Mac’s IP address (find it with ipconfig getifaddr en0 for Wi-Fi or en1 for Ethernet). You’ll be prompted for your macOS password.

If you want key-based authentication (more secure than passwords), generate an SSH key pair on the client with ssh-keygen, then copy the public key to the Mac using ssh-copy-id (if available) or manually append it to ~/.ssh/authorized_keys.

Common Problems and Fixes

  • “Connection refused”—SSH isn’t running. Check Remote Login is on, and the firewall isn’t blocking port 22.
  • “Permission denied”—Wrong username or password. Make sure you’re using the exact macOS account name (case-sensitive).
  • Can’t connect from outside your network—Your router likely needs port forwarding for port 22 to the Mac’s local IP. For security, use a VPN instead of exposing SSH directly to the internet.
  • Slow or hanging connections—May be DNS issues. Try connecting with the IP address instead of a hostname.
  • SSH works but SCP/SFTP fails—These use the same SSH service, so if SSH works, they should too. Check the syntax; for example, scp file.txt user@mac:/path/.

Security Considerations

Enabling SSH opens a network port. Anyone who can reach that port can attempt to log in. To reduce risk:

  • Use strong, unique passwords or, better, set up SSH key authentication.
  • Disable SSH when you don’t need it.
  • Consider changing the default port (22) to a non-standard one—though this is security by obscurity and not a substitute for proper hardening.
  • Use a firewall (macOS’s built-in one or a third-party) to restrict which IPs can connect.
  • Keep macOS updated to get security patches for OpenSSH.

Note that enabling SSH does not change any other system settings. It only starts the SSH service.

Alternatives to SSH on Mac

If you need remote access but SSH isn’t suitable, consider:

  • Screen Sharing (VNC): Built into macOS, gives a graphical desktop. Enable it in Sharing settings. Less secure than SSH—use a VPN or SSH tunnel.
  • Remote Management: For Apple Remote Desktop, also in Sharing settings.
  • Third-party tools: TeamViewer, AnyDesk, etc., offer easy remote desktop but may require installing software.

Frequently Asked Questions

Is SSH enabled by default on Mac?

No. Remote Login (SSH) is off by default on all macOS versions. You must enable it either via System Settings > Sharing or the systemsetup command.

What is the default SSH port on Mac?

Port 22, the standard SSH port. You can change it by editing /etc/ssh/sshd_config (you’ll need to restart the service afterward), but this is rarely necessary.

Can I enable SSH without sudo?

No. Changing system settings like Remote Login requires administrator privileges. You must be an admin user and enter your password with sudo.

How do I find my Mac’s IP address from the command line?

Use ipconfig getifaddr en0 for Wi-Fi or ipconfig getifaddr en1 for Ethernet. Alternatively, ifconfig shows all interfaces.

Does enabling SSH affect battery life?

Negligibly. The SSH daemon uses very little CPU when idle. It only consumes resources when active connections exist.

Can I use SSH to access my Mac from anywhere?

Yes, if you set up port forwarding on your router or use a VPN. However, exposing SSH to the internet increases security risks, so use a strong password or keys and consider a non-standard port.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →