SSH commands

Generate SSH keys, connect to GitHub and servers, copy files securely and forward ports through an SSH tunnel.

9 commands

Generate an SSH key

macOSWindowsLinux

Creates a modern, secure key pair in ~/.ssh. Press Enter to accept the default location.

ssh-keygen -t ed25519 -C ""

Copy your public key (macOS)

macOS

Puts the public key on the clipboard to paste into GitHub, GitLab or a server.

pbcopy < ~/.ssh/id_ed25519.pub

Copy your public key (Windows)

WindowsPowerShell

Puts the public key on the clipboard.

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard

Remember the key passphrase (macOS)

macOS

Stores the passphrase in Keychain so you’re not asked every time.

ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Test your GitHub SSH connection

macOSWindowsLinux

Confirms GitHub accepts your key.

ssh -T git@github.com

Install your key on a server

macOSLinux

Lets you log in without a password from now on.

ssh-copy-id @

Upload a file to a server

macOSWindowsLinux

Copies a file over SSH. Add -r for folders.

scp @:

Forward a remote port to your machine

macOSWindowsLinux

Open http://localhost:8080 to reach the server’s port 80 through an encrypted tunnel.

ssh -L :localhost: @

Fix "permissions are too open"

macOSLinux

SSH refuses private keys other users can read.

chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519

Every command copies as plain, clean text: no curly quotes, no long dashes, no invisible characters.

Related guides