Jump to content

SSH: Difference between revisions

From Archive
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..."
 
No edit summary
 
Line 11: Line 11:


==== Get IP Address ====
==== Get IP Address ====
<syntaxhighlight lang="bash">
<pre>
ifconfig | grep "inet " | grep -v 127.0.0.1
ifconfig | grep "inet " | grep -v 127.0.0.1
</syntaxhighlight>
</pre>


==== Prevent Sleep (Optional) ====
==== Prevent Sleep (Optional) ====
<syntaxhighlight lang="bash">
<pre>
# Disable sleep on AC power
# Disable sleep on AC power
sudo pmset -c sleep 0
sudo pmset -c sleep 0
Line 23: Line 23:
# Keep WiFi alive during sleep
# Keep WiFi alive during sleep
sudo pmset -c womp 1
sudo pmset -c womp 1
</syntaxhighlight>
</pre>


=== On Client Mac (Controller) ===
=== On Client Mac (Controller) ===


==== Test Connection ====
==== Test Connection ====
<syntaxhighlight lang="bash">
<pre>
</syntaxhighlight>
</pre>


==== Setup SSH Keys ====
==== Setup SSH Keys ====
<syntaxhighlight lang="bash">
<pre>
# Generate key if needed
# Generate key if needed
ls ~/.ssh/id_rsa.pub || ssh-keygen -t rsa -b 4096
ls ~/.ssh/id_rsa.pub || ssh-keygen -t rsa -b 4096
Line 39: Line 39:
# Copy key to target Mac
# Copy key to target Mac
ssh-copy-id [email protected]
ssh-copy-id [email protected]
</syntaxhighlight>
</pre>


==== Create SSH Config ====
==== Create SSH Config ====
Add to <code>~/.ssh/config</code>:
Add to <code>~/.ssh/config</code>:
<syntaxhighlight lang="text">
<pre>
Host imac
Host imac
     HostName 192.168.1.XXX
     HostName 192.168.1.XXX
Line 49: Line 49:
     ServerAliveInterval 30
     ServerAliveInterval 30
     ServerAliveCountMax 3
     ServerAliveCountMax 3
</syntaxhighlight>
</pre>


Now connect with: <code>ssh imac</code>
Now connect with: <code>ssh imac</code>
Line 57: Line 57:
==== Install Mosh ====
==== Install Mosh ====
On both machines:
On both machines:
<syntaxhighlight lang="bash">
<pre>
brew install mosh
brew install mosh
</syntaxhighlight>
</pre>


Connect with: <code>mosh [email protected]</code>
Connect with: <code>mosh [email protected]</code>
Line 66: Line 66:


==== SSH Connection Refused ====
==== SSH Connection Refused ====
<syntaxhighlight lang="bash">
<pre>
# Check if SSH is running
# Check if SSH is running
sudo systemsetup -getremotelogin
sudo systemsetup -getremotelogin
Line 75: Line 75:
# Check firewall
# Check firewall
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
</syntaxhighlight>
</pre>


==== WiFi Keepalive Script ====
==== WiFi Keepalive Script ====
<syntaxhighlight lang="bash">
<pre>
cat > ~/keepalive.sh << 'EOF'
cat > ~/keepalive.sh << 'EOF'
#!/bin/bash
#!/bin/bash
Line 89: Line 89:
chmod +x ~/keepalive.sh
chmod +x ~/keepalive.sh
nohup ~/keepalive.sh &
nohup ~/keepalive.sh &
</syntaxhighlight>
</pre>


[[Category:SSH]]
[[Category:SSH]]
[[Category:macOS]]
[[Category:macOS]]
[[Category:Networking]]
[[Category:Networking]]

Latest revision as of 13:32, 14 August 2025

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 &