The easiest way to log in to your sites with an SSH key is to add it in the Console. Open Settings › SSH Keys, paste your public key, and choose which teams or sites it goes to. The Console puts it on those sites for you and takes it off when someone loses access. See Managing SSH keys in the Console.
If you'd rather manage keys yourself, for example for a deployment tool that isn't tied to a person, you can still add a key from the command line, exactly as you would on any Linux server. The steps are below.
Before you start
Your site's SSH details. Open the site in the Console, then under Hosting select SSH / SFTP. You will need the Host, Port, Username, and Password shown there. See Connecting over SSH and SFTP if you have not used them before.
A terminal. Terminal on macOS, any Linux shell, or PowerShell on Windows 10 and later, which all include the OpenSSH tools used below.
In the commands below, replace USERNAME and HOST with the values from your site's SSH / SFTP page.
Step 1: Create a key pair
Skip this step if you already have a key you want to use.
Run:
ssh-keygen -t ed25519 -C "[email protected]"Press Enter to accept the default file location. You can add a passphrase for extra protection, or leave it empty.
This creates two files in your
.sshfolder:id_ed25519is your private key, which stays on your computer and is never shared.id_ed25519.pubis your public key, which is the one you add to the site.Display the public key so you can copy it:
cat ~/.ssh/id_ed25519.pub
The public key is a single line that starts with ssh-ed25519. Copy the whole line, including the comment at the end.
Step 2: Add the public key to your site by hand
Pick whichever option suits you. Both do the same thing.
Option A: use ssh-copy-id (macOS and Linux)
Run:
ssh-copy-id -i ~/.ssh/id_ed25519.pub USERNAME@HOSTWhen prompted, enter the site's SSH / SFTP password from the Console. The tool copies the key into place and sets the right permissions for you.
Option B: add it by hand (works everywhere, including Windows)
Log in to the site with the password:
ssh USERNAME@HOSTRun these four commands, pasting your public key in place of
PASTE_YOUR_PUBLIC_KEY_HERE:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "PASTE_YOUR_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
When the commands finish, type exit to log out.
Each key goes on its own line in authorized_keys, so you can add a key for every person or tool that needs access.
Step 3: Connect with the key
Run:
ssh USERNAME@HOSTYou should land on the server without being asked for a password. If your key is not in the default location, point to it:
ssh -i /path/to/private_key USERNAME@HOST
Most SFTP clients, including FileZilla and Cyberduck, can use the same key. Choose key-based authentication in the client's connection settings and select your private key file.
Good to know
The password keeps working. Adding a key does not disable password logins for the site.
Keys survive a password rotation. Rotating the SSH / SFTP password in the Console doesn't remove any keys. Keys added in the Console come off when you delete them or when the person loses access. Keys added by hand stay until you delete their line from
~/.ssh/authorized_keys. See How do I update my SSH Password?Keys added by hand are per site. Every site has its own username and home folder, so add your key to each site you want to reach. Keys added in the Console can cover a whole team at once.
The Console shows keys you add by hand. They're listed under Added outside Console on the site's SSH / SFTP page, for reference. The Console never changes or removes them.
Scripts and deployment tools use the server's default PHP. When a command is run non-interactively over SSH, for example by a deployment tool or a cron job,
phpis the server's default command-line version rather than the version your site is set to. To use a specific version, call it directly, such as/usr/local/php84/bin/php. Runls /usr/local/php*/bin/phpto see the versions available.
Troubleshooting
Still asked for a password. The server ignores the key file if the permissions are wrong. Log in with the password and run
chmod 700 ~/.sshandchmod 600 ~/.ssh/authorized_keysagain, and check the key is on one line with nothing added. Also confirm you are connecting with the site's username, not your Console email.Permission denied (publickey). The private key you are using does not match a key on the site, or the username is wrong. Run
ssh -v USERNAME@HOSTto see which key your computer is offering.Using PuTTY on Windows. Copy the key from PuTTYgen's Public key for pasting into OpenSSH authorized_keys file box. The saved .ppk or .pub file from PuTTYgen is in a different, multi-line format that the server will not accept.
Connection refused after several failed attempts. Repeated failed logins temporarily block your IP address. Wait a while before trying again, or contact us and we will lift the block.
Need help?
If you get stuck at any step, our support team is available 24/7 with a one-hour response time. Reach out from your dashboard.