
When you want to connect to a VPS or cloud server and run commands, the basic tool you use is the SSH (Secure Shell) protocol. SSH sets up an encrypted channel between two machines so your commands and data can't be read on the network. This guide covers what SSH is, creating a key and security settings.
What is SSH?
SSH is a protocol that lets you connect securely from your computer to the command line of a remote machine. It is standard for server management, file transfer (SCP/SFTP) and automation. It replaced old unencrypted methods such as Telnet. For server concepts see our VPS and Linux guides.
How does it work?
- 1
The client connects to the server's address and port
- 2
The server verifies its identity (host key)
- 3
An encrypted channel is set up
- 4
The user proves identity with a password or key
- 5
A command-line session opens
On the first connection you are asked to confirm the server's fingerprint; this is to make sure you are connecting to the right server.
Password or key?
| Feature | Password | SSH key |
|---|---|---|
| Security | Open to guessing and brute force | Much stronger |
| Convenience | Typed each time | Set up once, comfortable to use |
| Automation | Hard | Easy |
| Risk | Weak password | Theft of the private key |
Creating an SSH key
A key pair has two parts: the private key (stays with you) and the public key (goes on the server).
- Open a terminal (PowerShell on Windows, Terminal on macOS/Linux).
- Run the key-creation command:
ssh-keygen -t ed25519 - Confirm the file location and set a strong passphrase.
- Copy the public key to the server (for example
ssh-copy-id user@server). - Connect with
ssh user@serverto test.
Don't share the private key, email it or put it in a public repository (see our API key security guide).
Basic commands
| Command | Function |
|---|---|
ssh user@server | Connects to the server |
ssh -p 2222 user@server | Connects on a different port |
scp file user@server:/path | Copies a file |
sftp user@server | A file transfer session |
exit | Closes the session |
Security settings
- Use key login; turn off password login.
- Disable direct root login; connect as a normal user and elevate.
- Changing the default port reduces noise but isn't security on its own.
- Allow only needed addresses with a firewall (see our firewall guide).
- Use tools that block failed logins.
- Keep the server updated.
- Clean up unused keys regularly.
- You can add two-factor authentication (see our two-factor guide).
Common problems
- Connection refused: the service may be off, or there's a port or firewall problem.
- Permission denied: the username, key or permissions may be wrong.
- Host key changed warning: the server may have been reinstalled; but also consider a real attack.
- Timeout: may be a network or firewall problem.
Common mistakes
- Leaving root login open with a weak password.
- Sharing the private key or uploading it to a repository.
- Not putting a passphrase on the key.
- Accepting the fingerprint warning without examining it.
- Changing settings without a backup access path and locking yourself out.
Frequently asked questions
Is SSH the same as a VPN? No; SSH is a secure command-line connection to one machine, a VPN tunnels all network traffic.
Does SSH work on Windows? Yes, modern Windows versions have a built-in SSH client.
Is changing the port enough? No; keys and a firewall are needed.
Summary
SSH is the standard way to connect to servers securely. Use key login, protect the private key, disable password and root login and keep the server updated.
Serkan Akyürek is the founder and author of toolrota; he writes step-by-step guides on Excel, AI, the cloud, personal finance and digital security.