Customer Support

  1. Support
  2. How can I add an ssh key to my Linux server if I have a Mac or Linux operating system?
  1. Home
  2. Dedicated / VPS Management
  3. How can I add an ssh key to my Linux server if I have a Mac or Linux operating system?
  1. Home
  2. myTophost Panel
  3. Management
  4. How can I add an ssh key to my Linux server if I have a Mac or Linux operating system?
  1. Home
  2. myTophost Panel
  3. How can I add an ssh key to my Linux server if I have a Mac or Linux operating system?

How can I add an ssh key to my Linux server if I have a Mac or Linux operating system?

Using SSH keys is a secure and reliable way to connect to your VPS over SSH without a password. In this guide, you’ll see how to create SSH keys on Linux, and macOS, and how to use them to connect.

Create an SSH key on Linux or macOS

  1. Open Terminal.
Αυτή η εικόνα δεν έχει ιδιότητα alt. Το όνομα του αρχείου είναι 1572353623039.png
  1. Run: ssh-keygen -t ed25519
  2. Follow the on-screen steps for a passphrase (optional).
  3. The files will be saved in ~/.ssh:
    • id_ed25519 (private key)
    • id_ed25519.pub (public key)

Notes:

  • -t ed25519: Sets the key type. ed25519 is the most secure modern choice.
  • -f /path/id_ed25519: (optional) changes the save location.
  • -i -f: (optional) converts an existing key to another format (e.g., SSH2 ➝ OpenSSH).

You’ll also see a fingerprint and a randomart image, useful for verifying the key on remote servers.


Add your public key to the VPS

There are two methods:

1. Automatically via ssh-copy-id

  1. Connect to the VPS: ssh user@ip
  2. If not present, create the folder: mkdir ~/.ssh && touch ~/.ssh/authorized_keys
  3. Log out: exit
  4. Run: ssh-copy-id user@ip or sudo ssh-copy-id -i ~/.ssh/id_ed25519.pub user@ip
  5. Optional: add -p 1234 if you use a custom port.
  6. The output will be similar to the screenshot. If prompted to confirm, type yes.

If you see no identities found, make sure the key is in the correct folder or specify the path with -i.

For example:

sudo ssh-copy-id -i ~/.ssh/id_rsa.pub user@123.123.123.123 
sudo ssh-copy-id -i /etc/keys/id_rsa.pub user@123.123.123.123 
sudo ssh-copy-id -i /home/root/id_rsa.pub user@123.123.123.123


2. Manually

  1. Connect to the VPS via SSH.
  2. Create (if missing): mkdir ~/.ssh && touch ~/.ssh/authorized_keys
  3. Open your public key on your computer (e.g., id_ed25519.pub) and copy it.
  4. Open the file: nano ~/.ssh/authorized_keys
  5. Paste the key and save (Ctrl + X ➝ Y ➝ Enter).

Disable password logins

For maximum security, it’s recommended to disable password-based SSH logins:

  1. Edit the file: sudo nano /etc/ssh/sshd_config
  2. Find and set: PasswordAuthentication no
  3. Save and close (Ctrl + X ➝ Y ➝ Enter)
  4. Restart SSH:
    • Ubuntu/Debian: sudo systemctl restart ssh
    • CentOS/AlmaLinux: sudo systemctl restart sshd

You haven't found what you are looking for?

Contact our experts, they will be happy to help!

Contact us