SSH (Secure Shell) lets you securely log into a remote Linux server from your own machine, giving you a command-line terminal as if you were sitting at that server. This guide walks you through the entire process—from generating a key pair to connecting for the first time—so you can manage files, run commands, and administer your server remotely.
What You’ll Need
- A remote Linux server (e.g., a VPS, cloud instance, or a machine on your network) with SSH enabled (usually the default).
- The server’s IP address or hostname, and the username you’ll log in as (often
rootor a user with sudo privileges). - A local machine with an SSH client. Linux and macOS have
sshbuilt in; Windows 10/11 includes OpenSSH, or you can use PowerShell or the Windows Terminal. - Optional but recommended: a password or an SSH key pair for authentication.
Step-by-Step
- Open a terminal on your local machine. On Linux, press
Ctrl+Alt+T; on macOS, open Terminal from Applications; on Windows, open PowerShell or Windows Terminal. - Check if SSH is installed by typing
ssh -Vand pressing Enter. You should see a version number. If not, install OpenSSH client via your package manager (e.g.,sudo apt install openssh-clienton Debian/Ubuntu). - Find your server’s IP address or hostname. You should have this from your hosting provider or network admin. For example,
192.168.1.100orserver.example.com. - Connect using password authentication (simplest for first time): type
ssh username@server_ip, e.g.,ssh root@192.168.1.100. Press Enter. - Accept the host key when prompted. The first time you connect, SSH shows a fingerprint and asks if you trust the host. Type
yesand press Enter. This stores the host key in~/.ssh/known_hosts. - Enter your password when asked. You won’t see any characters as you type—that’s normal. Press Enter after typing it.
- You’re now logged in. You’ll see a shell prompt like
root@server:~#. You can run commands, navigate files, and manage the server. - To exit, type
exitor pressCtrl+D. This closes the SSH session and returns you to your local terminal. - Set up SSH key authentication for more secure and convenient logins (recommended). On your local machine, generate a key pair with
ssh-keygen -t rsa -b 4096. Press Enter to accept the default file location (~/.ssh/id_rsa) and optionally set a passphrase. - Copy your public key to the server using
ssh-copy-id username@server_ip. This will ask for your password once, then adds your public key to the server’s~/.ssh/authorized_keysfile. - Test key-based login by running
ssh username@server_ipagain. If you set a passphrase, you’ll be asked for it; otherwise, you should log in without a password. - Optional: Disable password authentication on the server for better security. Edit
/etc/ssh/sshd_configon the server, setPasswordAuthentication no, then restart SSH withsudo systemctl restart sshd. Make sure your key works before doing this!
Common Mistakes
- Typing the wrong username or IP. Double-check the exact spelling and case—usernames are case-sensitive.
- Forgetting the port. If your server uses a non-default SSH port (not 22), you must specify it with
-p port_number, e.g.,ssh -p 2222 user@server. Otherwise, the connection will time out. - Ignoring the host key warning. If you see a warning that the host key has changed, it could mean a man-in-the-middle attack or the server was reinstalled. Don’t blindly accept it—verify with your server provider if needed.
- Using the wrong key file. If you have multiple keys, specify the one to use with
-i /path/to/key, e.g.,ssh -i ~/.ssh/mykey user@server. - Permissions issues on the server. Your
~/.sshdirectory on the server must have permissions700andauthorized_keysmust be600. If not, SSH will refuse the key. Fix withchmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys.
Tips
- Use SSH keys instead of passwords. They’re more secure and allow automation. Always protect your private key with a strong passphrase.
- Create a config file (
~/.ssh/config) to simplify connections. For example, addHost myserver,HostName 192.168.1.100,User root,Port 22. Then you can just typessh myserver. - Use
ssh -vfor verbose output when debugging connection issues. It shows detailed steps of the handshake. - Keep your system updated. Regularly update OpenSSH on both client and server to get security patches.
- Use a terminal multiplexer like
tmuxorscreenon the server so your sessions survive disconnects and you can run long processes.
Troubleshooting
- Connection refused or timeout. Check that the SSH service is running on the server (
sudo systemctl status sshd). Ensure the firewall allows port 22 (or your custom port). On many cloud providers, you must open the port in their security group settings. - Permission denied (publickey,password). This usually means the username or password is wrong, or the server doesn’t allow password auth. Try
ssh -vto see what’s happening. If using a key, ensure the public key is correctly placed in~/.ssh/authorized_keyson the server. - Host key verification failed. This happens when the server’s key changed. If you trust the server, remove the old key from
~/.ssh/known_hostsusingssh-keygen -R server_ipand try again. - Connection closed by remote host. This could be due to a firewall, a fail2ban rule, or the server rejecting your IP. Check server logs with
sudo tail -f /var/log/auth.log(on Debian/Ubuntu) or/var/log/secure(on RHEL/CentOS). - Slow connection. Try adding
-o ConnectTimeout=10to your command to set a timeout. Also check if your local network is slow or if the server is under load.
Frequently Asked Questions
Can I SSH into a server without a password?
Yes, by using SSH key authentication. Generate a key pair, copy the public key to the server’s authorized_keys file, and you can log in without a password (unless you set a passphrase on your key).
What is the default SSH port?
The default is port 22. If your server uses a different port, you must specify it with the -p option.
How do I copy files over SSH?
Use scp (secure copy) or rsync. For example, scp file.txt user@server:/path/to/destination copies a file to the server. To download, reverse the order.
Why do I get a ‘Permission denied’ error even with the correct password?
This can happen if the server has disabled password authentication, if the account is locked, or if you’re using the wrong username. Check the server’s SSH config and logs for details.
Can I SSH from Windows?
Yes, Windows 10 and 11 include OpenSSH client. Open PowerShell or Windows Terminal and use the same ssh command. You can also use third-party tools like PuTTY.
How do I change my SSH password?
Log in via SSH and run the passwd command. You’ll be prompted to enter your current password and then set a new one.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- How to Factory Reset iPad If You Forgot Password
- Ubuntu in Windows Store: Which Editions Work?
- Secure Guest Account on Windows 11: Step-by-Step
- Stop Outlook From Changing Hyperlink Font
- Hiberfil.sys: What It Is & How to Delete It
- How to Make a Mask on Snapchat: Step-by-Step