Jump to content

SSH

From Archive

Setting up SSH in OS X

Quick setup guide for enabling SSH access to a Mac from another machine.

On Target Mac (Server)

Enable SSH

  • macOS Ventura/Sonoma: System Settings → General → Sharing → Toggle "Remote Login" ON
  • Older macOS: System Preferences → Sharing → Check "Remote Login"
  • Note the IP address displayed (e.g., 192.168.1.XXX)

Get IP Address

ifconfig | grep "inet " | grep -v 127.0.0.1

Prevent Sleep (Optional)

# Disable sleep on AC power
sudo pmset -c sleep 0
sudo pmset -c disablesleep 1

# Keep WiFi alive during sleep
sudo pmset -c womp 1

On Client Mac (Controller)

Test Connection

ssh [email protected]

Setup SSH Keys

# Generate key if needed
ls ~/.ssh/id_rsa.pub || ssh-keygen -t rsa -b 4096

# Copy key to target Mac
ssh-copy-id [email protected]

Create SSH Config

Add to ~/.ssh/config:

Host imac
    HostName 192.168.1.XXX
    User username
    ServerAliveInterval 30
    ServerAliveCountMax 3

Now connect with: ssh imac

For Unstable Connections

Install Mosh

On both machines:

brew install mosh

Connect with: mosh [email protected]

Troubleshooting

SSH Connection Refused

# Check if SSH is running
sudo systemsetup -getremotelogin

# Force enable
sudo systemsetup -setremotelogin on

# Check firewall
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate

WiFi Keepalive Script

cat > ~/keepalive.sh << 'EOF'
#!/bin/bash
while true; do
    ping -c 1 192.168.1.1  # Router IP
    sleep 30
done
EOF

chmod +x ~/keepalive.sh
nohup ~/keepalive.sh &