SSH into your VPS from a Mac with Terminal
Connect to your Linux VPS from macOS with the built-in Terminal or iTerm2, create an SSH key, store its passphrase in the macOS Keychain and save shortcuts in your SSH config file.
- Beginner
- Linux VPS
- 4 min read
Every Mac comes with an SSH client built in, so you can manage a Linux VPS without installing anything. This guide shows how to connect from Terminal, set up key login, have macOS remember your key passphrase in the Keychain, and save shortcuts so a server is only two words away.
Before you start
- Your VPS IP address, username and password from the service page in your Dashboard.
- A Mac with a current version of macOS.
- Terminal (in Applications → Utilities, or press Cmd + Space and type
Terminal). iTerm2 is a popular free alternative with split panes and better search; everything below works the same in it.
Connect with a password
Open Terminal and run:
ssh [email protected]If your server listens on a different SSH port, add -p:
ssh -p 2222 [email protected]On the first connection, macOS shows the server's key fingerprint and asks:
Are you sure you want to continue connecting (yes/no/[fingerprint])?Type yes and press Return. The key is saved in ~/.ssh/known_hosts so you are warned if it ever changes.
Enter your password. Nothing appears while you type, which is normal. You can paste it with Cmd + V. When the prompt changes to something like root@vps1:~#, you are in.
Type exit or press Ctrl + D to log out.
Create an SSH key
Keys are safer than passwords. Generate an Ed25519 key:
ssh-keygen -t ed25519 -C "you@mac"Accept the default path (~/.ssh/id_ed25519) and set a passphrase. You now have:
~/.ssh/id_ed25519: the private key. Keep it on your Mac.~/.ssh/id_ed25519.pub: the public key, which goes on the server.
Copy the public key to the server with ssh-copy-id, which macOS includes:
ssh-copy-id [email protected]For a custom port:
ssh-copy-id -p 2222 [email protected]Enter the server password one last time. Now ssh [email protected] asks for the key's passphrase instead. For background on keys, see Set up SSH keys.
Store the passphrase in the Keychain
Apple's SSH can save your key passphrase in the macOS Keychain, so you never have to type it again on this Mac. Add the key once:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519On older macOS versions the option is -K instead of --apple-use-keychain.
To load the key from the Keychain automatically after every restart, add these lines at the top of ~/.ssh/config (create the file if it does not exist):
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519Save shortcuts in the SSH config file
Add a block for each server to ~/.ssh/config:
Host web
HostName 203.0.113.10
User deploy
Port 22Now connect with:
ssh webThe shortcut works for scp, sftp and rsync too, for example scp backup.tar.gz web:~/. Make sure the file is private:
chmod 600 ~/.ssh/configSee Use the SSH config file to save hosts for more options.
Terminal tips on a Mac
- Copy and paste: Cmd + C and Cmd + V. Ctrl + C sends an interrupt to the server, it does not copy.
- Option as Meta: some editors and shells use the Alt key. In Terminal, go to Settings → Profiles → Keyboard and tick Use Option as Meta key. In iTerm2, set the left Option key to Esc+ under Profiles → Keys.
- Keep idle sessions alive: add
ServerAliveInterval 60underHost *in~/.ssh/configto stop Wi-Fi changes and NAT timeouts dropping a quiet connection. - Several servers at once: Cmd + T opens a new tab. In iTerm2, Cmd + D splits the window.
Check it works
Run a command on the server without opening a session:
ssh web 'hostname && uptime'You should see the server's hostname and uptime with no password or passphrase prompt.
Troubleshooting
- `Operation timed out` or `Connection refused`: the server is off, the IP or port is wrong, or a firewall blocks SSH. Check the server in the Dashboard. See Fix SSH connection refused or timed out.
- `WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!`: expected after an OS reinstall. Remove the old key with
ssh-keygen -R 203.0.113.10. If you did not reinstall, investigate before connecting. - `Permission denied (publickey)`: the server does not have your public key for that user. Run
ssh-copy-idagain, or check~/.ssh/authorized_keyson the server. - `Bad configuration option: usekeychain`: you are using a non-Apple OpenSSH, for example from Homebrew. Add
IgnoreUnknown UseKeychainabove theUseKeychainline, or use/usr/bin/ssh. - Asked for the passphrase after every restart: add
UseKeychain yesandAddKeysToAgent yesto your config as shown above.
Next steps
- Compare plans for your next server on Linux VPS.
Was this guide helpful?
Still stuck?
Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.
Related guides
Getting started
Edit files with nano: a beginner's guide
Open, edit, search and save files with the nano text editor on a Linux server, including cutting and pasting lines, showing line numbers and safely editing system config files with sudo.
- Beginner
- Linux VPS
- 5 min read
Getting started
Your first hour with a new RunRacks server
A step-by-step roadmap for the first hour after your RunRacks server is delivered, from finding your login details to changing the password, updating the OS and picking your next guides.
- Beginner
- All
- 5 min read
Getting started
How to choose a server location
Pick a data center location based on where your users, broker or team are, confirm it with ping tests, and weigh the legal and latency points that come with each choice.
- Beginner
- All
- 4 min read