Jump to content

SSH

From Archive
Revision as of 13:31, 14 August 2025 by Ejfox (talk | contribs) (Created page with "== 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., <code>192.168.1.XXX</code>) ==== Get IP Address ==== <syntaxhighlight lang="bash"> ifconfig | grep "in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

<syntaxhighlight lang="bash"> ifconfig | grep "inet " | grep -v 127.0.0.1 </syntaxhighlight>

Prevent Sleep (Optional)

<syntaxhighlight lang="bash">

  1. Disable sleep on AC power

sudo pmset -c sleep 0 sudo pmset -c disablesleep 1

  1. Keep WiFi alive during sleep

sudo pmset -c womp 1 </syntaxhighlight>

On Client Mac (Controller)

Test Connection

<syntaxhighlight lang="bash"> ssh [email protected] </syntaxhighlight>

Setup SSH Keys

<syntaxhighlight lang="bash">

  1. Generate key if needed

ls ~/.ssh/id_rsa.pub || ssh-keygen -t rsa -b 4096

  1. Copy key to target Mac

ssh-copy-id [email protected] </syntaxhighlight>

Create SSH Config

Add to ~/.ssh/config: <syntaxhighlight lang="text"> Host imac

   HostName 192.168.1.XXX
   User username
   ServerAliveInterval 30
   ServerAliveCountMax 3

</syntaxhighlight>

Now connect with: ssh imac

For Unstable Connections

Install Mosh

On both machines: <syntaxhighlight lang="bash"> brew install mosh </syntaxhighlight>

Connect with: mosh [email protected]

Troubleshooting

SSH Connection Refused

<syntaxhighlight lang="bash">

  1. Check if SSH is running

sudo systemsetup -getremotelogin

  1. Force enable

sudo systemsetup -setremotelogin on

  1. Check firewall

sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate </syntaxhighlight>

WiFi Keepalive Script

<syntaxhighlight lang="bash"> cat > ~/keepalive.sh << 'EOF'

  1. !/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 & </syntaxhighlight>