grayform b33

← guides

Remote access · 15 minutes

Set up an SSH server on your PC

Install it, turn on keys only, and keep the firewall tight. Windows, macOS and Linux.

SSH lets you open a terminal on your computer from another device. Set it up once, and set it up safely.

Two rules for this whole guide: use keys, not passwords, and never open the port to the public internet.

Windows

Install

  1. Open Settings > System > Optional features (on Windows 10: Apps > Optional features).
  2. Choose View features (or Add a feature), search for OpenSSH Server, install it.

Or do it in an admin PowerShell:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Start it and keep it on

Start-Service sshd
Set-Service -Name sshd -StartupType Automatic

Add your key

Follow the key steps in the Grayform Shell guide. Admin accounts use C:\ProgramData\ssh\administrators_authorized_keys, and need the icacls line.

Keys only

  1. Open the config file as admin:
notepad C:\ProgramData\ssh\sshd_config
  1. Make sure these lines exist and are not commented out with #:
PasswordAuthentication no
PubkeyAuthentication yes
  1. Check the file for mistakes, then restart:
sshd -t
Restart-Service sshd

Test a key login from another device before you close your current session.

Firewall: private networks only

The installer adds a rule that may allow all networks. Narrow it:

Set-NetFirewallRule -Name OpenSSH-Server-In-TCP -Profile Private

If you use Tailscale, you can go further and allow only Tailscale's address range, which is 100.64.0.0/10:

Set-NetFirewallRule -Name OpenSSH-Server-In-TCP -Profile Any -RemoteAddress 100.64.0.0/10

Only do the second one if you reach the PC solely over Tailscale. Otherwise you lock yourself out of home network access.

macOS

  1. Open System Settings > General > Sharing.
  2. Turn on Remote Login.
  3. Choose Only these users and add yourself.
  4. Add your key to ~/.ssh/authorized_keys.
  5. Edit /etc/ssh/sshd_config and set PasswordAuthentication no. Newer macOS also reads files in /etc/ssh/sshd_config.d/.

Linux

sudo apt install openssh-server
sudo systemctl enable --now ssh

On Fedora and similar: sudo dnf install openssh-server, and the service is named sshd.

Then in /etc/ssh/sshd_config set PasswordAuthentication no, and reload:

sudo sshd -t && sudo systemctl reload ssh

If you use a firewall such as ufw, allow SSH only from your own network or Tailscale.

Never do this

  • Do not forward port 22 on your router. Bots scan the internet for it all day.
  • Do not leave password login on.
  • Do not share your private key. Only the public half ever leaves its device.

To reach the PC from anywhere, use Tailscale instead (next guide).

If it does not work

  • Connection timed out: check Get-Service sshd shows Running, and that the firewall rule matches the network you are on.
  • Permission denied (publickey): the key is missing, on two lines, or in the wrong file for your account type. On Windows admin accounts, check the icacls line was run.
  • Service will not start: run sshd -t. It prints the line with the mistake.
  • Locked yourself out: sit at the computer, undo the last change to sshd_config, and restart the service.