SSH Key Guide: Connect to Linux Servers Securely
Key Takeaways
- SSH is the safest method for accessing Linux servers remotely.
- SSH keys provide greater security than passwords.
- You will learn how to generate an SSH key pair using ssh-keygen.
- Simple SSH commands will be used to connect to remote servers.
- Best practices will help manage files, execute commands, and secure your infrastructure.
Today, Passwords Aren't Enough
At this moment, millions of developers, system administrators, and DevOps engineers are logging into Linux servers using SSH. Whether it is for deploying a web application, managing a VPS, or learning Linux at home, SSH is the tool that will be used almost every day.
If passwords are still your method of authentication, you are not utilizing a more secure and convenient way. This SSH key guide will explain what SSH is, how it operates behind the scenes, and how to generate and use SSH keys with confidence.
What Is SSH (Secure Shell)?
SSH is a cryptographic network protocol that allows secure access and management of remote computers over an unsecured network.
SSH can be thought of as a private, encrypted tunnel that connects your computer to a remote server. Even if someone intercepts the traffic, they are unable to read the data as it is encrypted.
Common uses include the management of Linux servers, deployment of websites, secure file transfer, running remote commands, accessing cloud instances such as AWS, Azure, Google Cloud, and Git authentication with platforms like GitHub and GitHub.
Why Is SSH Better Than Telnet?
In the past, many administrators utilized Telnet for remote access. The issue with Telnet was that it sent all information, including usernames and passwords, in plain text.
SSH resolves this issue by encrypting all communication.
| Feature | SSH | Telnet |
|---|---|---|
| Encryption | Yes | No |
| Password Protection | Yes | No |
| Secure File Transfer | SCP / SFTP | No |
| Modern Standard | Yes | Obsolete |
How SSH Works
Imagine you are mailing a confidential document. Instead of sending it in a transparent envelope, you place it inside a secure box that only the recipient can open. This is similar to how SSH functions.
The SSH Connection Process
- The SSH client contacts the server.
- The server presents its public host key.
- The client verifies the server's identity.
- A secure encrypted session is established.
- Authentication takes place, either through password or SSH key.
- Commands and data travel through the encrypted tunnel.
From this point onward, everything that is typed is protected.
Understanding SSH Keys
SSH key authentication uses two keys that are mathematically linked:
- Private Key – Remains on your computer and should never be shared.
- Public Key – Copied to the remote server.
When a connection is made, the server verifies the ownership of the matching private key without transmitting it over the network. This method is secure and convenient.
Generate an SSH Key Pair
Most modern Linux distributions come with OpenSSH.
Open a terminal and run the command:
If Ed25519 is not supported by your system, you can use RSA:
You will be prompted to:
- Choose where to save the key, pressing Enter for the default location.
- Enter an optional passphrase for added security.
The default files will be:
- ~/.ssh/id_ed25519
- ~/.ssh/id_ed25519.pub
The .pub file is the public key.
Copy Your Public Key to a Server
If ssh-copy-id is available, use the command:
Otherwise, manually append the public key to the server's ~/.ssh/authorized_keys.
Make sure the permissions are correct:
$ chmod 600 ~/.ssh/authorized_keys
Incorrect permissions are a frequent cause of authentication failures.
How to Connect to a Server via SSH
The basic syntax for connecting is:
For example:
To specify a particular private key, use:
On the first connection, you will be asked to verify the server's fingerprint. Confirm this only if you trust the server.
Essential SSH Commands
| Command | Purpose |
|---|---|
| ssh user@host | Connect to a server |
| ssh -p 2222 user@host | Use a custom port |
| ssh -i key user@host | Specify a private key |
| ssh-keygen | Generate SSH keys |
| ssh-copy-id | Install your public key on a server |
| scp file user@host:/path | Copy files securely |
| sftp user@host | Start a secure file transfer session |
Managing a Remote Linux Server
Once connected, it is possible to perform everyday administrative tasks such as:
- Updating packages: sudo apt update && sudo apt upgrade
- Checking disk usage: df -h
- Monitoring memory: free -h
- Viewing running processes: top
- Restarting a service: sudo systemctl restart nginx
These commands are essential for remote server management.
Common SSH Errors and Fixes
- Permission denied (publickey) – Ensure the correct private key is being used. Check file permissions. Verify that the public key is present in authorized_keys.
- Connection refused – Confirm that the SSH service is running: sudo systemctl status ssh. Ensure the server's firewall allows port 22 or your custom SSH port.
- Host key verification failed – The server's host key has changed. Investigate the reason before removing the old key from your known_hosts file to avoid security risks.
SSH Security Best Practices
To improve server security:
- Use SSH keys instead of passwords whenever possible.
- Protect your private key with a passphrase.
- Disable root login over SSH if it is not necessary.
- Consider changing the default SSH port to reduce automated scanning, but this does not replace proper security measures.
- Keep OpenSSH updated with the latest security patches.
- Regularly review authentication logs.
Real-World Uses of SSH
SSH is used daily for:
- Deploying web applications
- Managing VPS and dedicated servers
- Connecting to Raspberry Pi devices
- Administering cloud instances
- Conducting secure Git operations with GitHub and GitLab
- Building home labs and learning Linux
Whether you are a student or an experienced engineer, SSH quickly becomes an essential tool.
Final Thoughts
SSH is much more than just a remote login utility; it serves as the foundation for secure Linux administration. Once you understand how SSH keys function and practice connecting to remote systems, you will acquire a skill that is valuable in web development, DevOps, cloud computing, and cybersecurity.
Begin by generating your own SSH key pair, connect to a test server, and experiment in a safe environment. The more that SSH is used, the more intuitive it becomes.
Reliable References
For additional reading, consult:
- The OpenSSH project documentation
- The OpenBSD ssh(1) and ssh-keygen(1) manual pages
- Your Linux distribution's official documentation, including Ubuntu, Debian, Fedora, and others.





