Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To connect to a Linux VPS, open a terminal on your computer and run ssh user@SERVER_IP. Replace user with the account created by your VPS provider and SERVER_IP with the server’s public IP address. If the server uses a private key, specify it with -i; if SSH listens on another port, add -p PORT.

The reliable setup is: create an Ed25519 key pair locally, install its public key on the VPS, make one test connection, then harden SSH without closing your working session.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What SSH does when you connect to a VPS

SSH (Secure Shell) creates an encrypted, authenticated terminal session between your computer and the VPS. The VPS runs the SSH server, normally called sshd; your computer runs the ssh client. After authentication, commands you type run on the VPS rather than on your local machine.

SSH authentication has two separate trust decisions:

  • Server identity: your client checks the VPS host key and asks you to accept its fingerprint the first time.
  • User identity: the server verifies your account password or your private key.

Do not confuse the host key with your login key. The host key identifies the server; your key pair proves that you are allowed to log in as a particular account.

What you need before starting

Requirement What to obtain
VPS address The public IPv4 or IPv6 address, or a DNS name that resolves to it.
Login account The provider-created non-root account, or root if direct root login is enabled.
SSH port Usually 22, unless the provider or administrator configured another port.
Initial authentication The temporary password, an injected public key, or console access for installing one.
Local SSH client A terminal with ssh and ssh-keygen. OpenSSH clients are available on common Linux and macOS systems and on current Windows installations that include OpenSSH.

Copy the IP address and account name exactly. A connection to the right IP with the wrong account can produce a misleading “permission denied” error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create an SSH key pair on your computer

Key authentication is preferable to repeatedly sending a VPS password. The standard command creates a modern Ed25519 key pair:

ssh-keygen -t ed25519 -C "you@example.com"
  1. Run the command in your local terminal, not in a shell on the VPS.
  2. When prompted for a file, press Enter to accept the default location, normally ~/.ssh/id_ed25519, or enter a distinct filename if you already use that path.
  3. Enter a strong passphrase. The private key stays on your computer; never paste it into a ticket, chat, or server configuration.

The command creates two files: id_ed25519 (private key) and id_ed25519.pub (public key). Share only the file ending in .pub.

Ed25519 is the usual recommendation in current setup guides. RSA 4096 is a fallback for an older system that cannot use Ed25519:

ssh-keygen -t rsa -b 4096 -C "you@example.com"

Keep a protected backup of the private key if losing access would be costly. A backup must be protected as carefully as the original.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install the public key on the VPS

The server must have your public key in the target account’s ~/.ssh/authorized_keys file. Choose one of these methods.

Method 1: Add the key during VPS creation

Many VPS control panels offer a public-key field when you create an instance. Paste the complete single-line contents of ~/.ssh/id_ed25519.pub. The provisioning system then writes it to the account’s authorized-keys file during the first boot. The exact control-panel labels and behavior vary, so confirm which account receives the key.

Method 2: Use ssh-copy-id

If you can make one initial login with the temporary password, run this on your local computer:

ssh-copy-id -i ~/.ssh/id_ed25519.pub root@YOUR_VPS_IP

Replace root with the account you intend to use. The helper appends the public key to that account’s remote authorized_keys file and normally asks for the current account password once. ssh-copy-id is a helper script, separate from the core OpenSSH command set.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a non-default port, pass the port through SSH options:

ssh-copy-id -i ~/.ssh/id_ed25519.pub -p PORT user@YOUR_VPS_IP

Method 3: Append the key manually

Use the VPS provider’s web console or an initial password login, then run these commands as the target account:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
cat >> ~/.ssh/authorized_keys

Paste the entire public-key line, press Enter, then finish the cat command with Ctrl-D. Set the file permission afterward:

chmod 600 ~/.ssh/authorized_keys

Do not wrap the key across lines or add quotation marks. If you are installing a key for another account as an administrator, place it in that account’s home directory and ensure that account owns the files; otherwise the SSH daemon may ignore them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connect to the VPS

Default port and account

ssh user@YOUR_VPS_IP

For a root session, the syntax is:

ssh root@YOUR_VPS_IP

Use the non-root sudo account instead when the provider created one or when direct root login is disabled.

Specify a private key

ssh -i ~/.ssh/id_ed25519 user@YOUR_VPS_IP

If the key has a non-default filename, replace the path with that filename. The -i option selects the identity file used by the client.

Specify a non-default port

ssh -p PORT user@YOUR_VPS_IP

You can combine both options:

ssh -i ~/.ssh/id_ed25519 -p PORT user@YOUR_VPS_IP

These options are defined by the OpenBSD ssh(1) client. A successful connection ends with a shell prompt from the VPS, such as user@server:~$. Commands such as hostname and whoami let you confirm where you are:

hostname
whoami

Handle the first host-key prompt safely

On the first connection, the client displays the server’s host-key fingerprint and asks whether to continue. Typing yes stores the host key in your local known_hosts file and proceeds to authentication.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not accept a fingerprint blindly for a sensitive server. Compare it with the fingerprint shown in the provider’s console or other trusted administrative channel. If the fingerprint changes later, stop and investigate before accepting the new key: the VPS may have been rebuilt, its address may now point to another machine, or a connection could be intercepted.

Make repeated connections easier with SSH config

You can define a short alias in ~/.ssh/config on your computer:

Host my-vps
    HostName YOUR_VPS_IP
    User user
    IdentityFile ~/.ssh/id_ed25519
    Port 22

Protect the directory and file if they do not already exist:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/config

After saving the entry, connect with:

ssh my-vps

Keep the alias configuration private. It contains connection details, although not the private key itself.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot common connection failures

“Connection timed out” or “No route to host”

  • Check that the VPS is running and that you copied the current public IP.
  • Confirm the port with the provider. Try -p PORT if SSH was configured away from 22.
  • Check network firewalls or security groups for an inbound rule allowing that port from your address.
  • Verify that you are using the correct address family. An unreachable IPv6 address can fail even when the VPS’s IPv4 address works.

“Connection refused”

The host is reachable, but no SSH service is accepting connections on that port. Check the port number, the VPS power state, and the SSH service through the provider’s console. A firewall can also actively reject the connection.

“Permission denied (publickey)”

This means the server did not accept the offered key. Check the following in order:

  1. Use the account that owns the installed key. A key placed in /root/.ssh/authorized_keys will not authenticate a different user.
  2. Explicitly select the matching private key with -i.
  3. On the server, ensure ~/.ssh is mode 700 and authorized_keys is mode 600.
  4. Make sure the public-key line is complete, unwrapped, and present in the expected account’s file.
  5. Confirm that the server permits public-key authentication and that you are connecting to the intended port.

If you still have a password or console session, use it to correct the files rather than deleting keys at random.

“Permission denied (password)”

Recheck the username, keyboard layout, and whether password authentication is enabled. A provider may have disabled root passwords while leaving a sudo account available.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!”

Do not bypass this warning automatically. Verify whether the VPS was rebuilt or its IP was reassigned. Remove the old entry only after confirming the change through a trusted channel, then reconnect so the new fingerprint can be recorded.

“No mutual signature algorithm”

Modern OpenSSH clients can reject legacy ssh-rsa signatures that rely on SHA-1. Prefer a new Ed25519 key. If an older system requires RSA, use an RSA key and server configuration that support the newer SHA-2 RSA signatures rather than weakening the client to accept obsolete algorithms.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Harden SSH after key login works

Do not change authentication settings until key login succeeds. Red Hat’s OpenSSH guidance specifically recommends testing the key connection in a second terminal first. Keep the original session open while you make and test changes; it is your recovery path if the new configuration is wrong.

Review the effective policy

The OpenBSD sshd_config(5) documentation lists PasswordAuthentication as enabled by default. Root-login defaults differ by distribution and release:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Documentation context Direct-root default described Meaning
Ubuntu Trusty sshd_config(5) yes The documented options also include without-password, which disables password authentication for root.
Red Hat Enterprise Linux 10 documentation prohibit-password Root may use key authentication, but not a password.

Do not infer the setting on your VPS from its distribution name alone. Inspect the active configuration and your provider’s image documentation.

Use a non-root administrator

For routine administration, create or use a named account with sudo privileges and connect as that user. Red Hat advises against direct root logins because a named account provides a clearer audit trail for privileged commands. Test that the account can run the required administrative commands before restricting root.

Apply a conservative SSH policy

After confirming a working key login for the intended administrator, the commonly used hardened settings are:

PermitRootLogin prohibit-password
PubkeyAuthentication yes
PasswordAuthentication no

These lines belong in the server’s SSH daemon configuration, commonly /etc/ssh/sshd_config. The exact include files and policy controls vary by distribution. A setting that disables password authentication will also disable password-based recovery, so verify every administrator’s key first.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reload and test without locking yourself out

  1. Save the configuration and leave your current SSH session open.
  2. Open a second terminal and connect with the administrator’s key.
  3. Only after the second login works, restart the SSH service. On Ubuntu and Debian, the documented command is systemctl restart ssh.
  4. If the second connection fails, use the still-open session or the provider console to restore the previous working configuration.

Changing the SSH port is not a substitute for authentication controls. If you do change it, update the firewall and every client configuration at the same time, then test a new session before closing the old one.

A safe first-connection checklist

  • Record the VPS IP, account name, and SSH port.
  • Create an Ed25519 key pair locally and protect its private-key passphrase.
  • Install only the .pub file on the target account.
  • Set ~/.ssh to 700 and authorized_keys to 600.
  • Verify the host fingerprint before accepting it.
  • Connect with ssh, then confirm the hostname and username.
  • Test key login in a second terminal.
  • Switch routine work to a named sudo account where possible.
  • Change password and root-login settings only after the key path is proven.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.