SSH Login for Beginners: Easy Setup & Troubleshooting Guide
SSH is the standard way to log in to a Linux server from another Linux machine.
In this article you’ll learn:
- How to connect from Linux → Linux using SSH
- How to set up key-based login (no password)
- Exactly what
ssh-copy-id user@server-ipdoes - A practical SSH troubleshooting cheat sheet (auth errors, permissions, firewall, etc.)
No fluff. Just what you actually need.
1. Mental model: what SSH is
SSH (Secure Shell) lets you open a secure terminal on another machine:
Your laptop ---> encrypted SSH ---> Remote Linux server- Default port: 22
- Program on your machine:
ssh - Program on the server:
sshd(SSH daemon)
You type commands on your computer; they run on the server.
2. One-time setup on the server (Ubuntu/Debian)
On the server (the machine you want to connect to):
# Install server
sudo apt update
sudo apt install -y openssh-server
# Make sure SSH is running and enabled
sudo systemctl enable --now ssh
sudo systemctl status sshFind the server’s IP address:
ip -4 addr | grep inetLook for something like:
192.168.x.x10.x.x.x172.16.x.x–172.31.x.x
If you use UFW firewall, allow SSH:
sudo ufw allow ssh # opens port 22
sudo ufw enable # if not already enabled
sudo ufw statusQuick troubleshooting (server setup)
ssh: connect to host ... port 22: Connection refused
→sshdnot running or listening.
Check:sudo systemctl status sshssh: connect to host ... port 22: No route to hostor timeout
→ network / firewall issue.
- Check you can ping:ping server-ip- Check firewall:sudo ufw status- If cloud VM: also check cloud security group rules.
3. First connection from Linux to Linux (with password)
On your client machine (your laptop / another Linux box):
ssh username@server-ipExample:
ssh ali@192.168.1.105First time, you’ll see a fingerprint question:
Are you sure you want to continue connecting (yes/no/[fingerprint])?Type:
yesThen enter the password of the user on the server (e.g. the password for ali on that server).
If it works → you now have a shell on the remote machine.
Troubleshooting (password connection)
Permission denied (publickey,password)
→ Common causes:
- Wrong username (e.g.rootvsali)
- Wrong password
- SSH configured to disallow password auth
Try:
ssh -v username@server-ip- The
-v(verbose) output will tell you why it failed (no matching auth methods, wrong password, etc.). username@server-ip: Name or service not known
→ Typo in hostname or DNS issue. Try using the raw IP address.
4. Key-based login: ssh-keygen + ssh-copy-id
Password login works, but keys are more secure and more convenient.
4.1 Generate a key pair on the client
On your Linux client (not on the server):
ssh-keygen -t ed25519 -C "my-laptop"- Press Enter to accept the default path (
~/.ssh/id_ed25519) - Set a passphrase (recommended)
This creates:
~/.ssh/id_ed25519→ private key (keep secret)~/.ssh/id_ed25519.pub→ public key (you copy this to servers)
Check:
ls -l ~/.sshYou should see the two files.
4.2 Copy key to server (what ssh-copy-id user@server-ip actually does)
Now run on your client:
ssh-copy-id username@server-ipExample:
ssh-copy-id ali@192.168.1.105You’ll be asked for the server password ONE LAST TIME.
What this command does internally:
- Connects to
username@server-ipusing SSH (with your password). - Creates the directory
~/.sshon the server (if missing). - Appends your public key (
id_ed25519.pub) to:
~/.ssh/authorized_keys # on the server4. Fixes permissions so SSH accepts it.
So after ssh-copy-id:
- Your public key is now trusted by the server.
- Your private key stays on your client.
You’re ready to log in without typing the account password.
Troubleshooting ssh-copy-id
ssh-copy-id: command not found
→ Install OpenSSH client tools:
sudo apt install openssh-clientPermission denied (publickey,password) during ssh-copy-id
→ Same as normal SSH:
- Wrong user / password
- Server disabled password login already
- Firewall / network issues
Fix SSH/password login first, then run ssh-copy-id.
- Still asks for a password after
ssh-copy-id?
Check on the server:
ls -ld ~/.ssh
ls -l ~/.ssh/authorized_keysPermissions should be:
~/.ssh -> 700 (drwx------)
~/.ssh/authorized_keys -> 600 (-rw-------)If not, fix them:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysAlso confirm your public key is there:
cat ~/.ssh/authorized_keysYou should see a long line starting with ssh-ed25519 or ssh-rsa.
4.3 Connect using the key (no account password)
Now, simply:
ssh username@server-ipSSH will:
- Read your private key (e.g.
~/.ssh/id_ed25519) - Prove to the server that you own the matching key
- Log you in without asking for the account password
(it may ask for your key passphrase, which is good)
For debug:
ssh -v username@server-ipLook for Offering public key and Authentication succeeded (publickey).
5. Optional: secure your SSH server
Once key-based login works reliably, you can harden SSH:
Get Aliakbar Hosseinzadeh’s stories in your inbox
Join Medium for free to get updates from this writer.
On the server:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo nano /etc/ssh/sshd_configMake sure you have:
Protocol 2
PermitRootLogin no
PasswordAuthentication no
ChallengeResponseAuthentication noThen restart:
sudo systemctl restart sshImportant safety tip:
- Keep one SSH session open while you restart SSH.
- Open a second terminal and test a new login.
- Only close the original session when you know the new setup works.
6. SSH Troubleshooting Cheat Sheet (auth, permissions, firewall)
Here’s a compact “fix it fast” section you can refer to anytime.
A. Cannot connect at all
Error:
ssh: connect to host X.X.X.X port 22: Connection refusedCheck:
sudo systemctl status ssh
sudo ss -tlnp | grep ':22'Fix:
sudo systemctl enable --now sshError:
ssh: connect to host X.X.X.X port 22: No route to host
# or timeoutCheck:
ping server-ip
sudo ufw status- If
pingfails → network problem / wrong IP. - If UFW is active and no rule for
22→ add:
sudo ufw allow sshIf it’s a cloud server, also check your cloud firewall / security group.
B. “Permission denied” / auth errors
Error:
Permission denied (publickey,password)- Check user + host
ssh -v username@server-ip- Did you type correct username? (e.g.
ubuntu,ec2-user,ali?) - Are you connecting to the right server?
2. Check server-side authorized_keys
On the server (using some working access, even console):
ls -ld ~/.ssh
ls -l ~/.ssh/authorized_keysPermissions must be:
.ssh -> 700
authorized_keys -> 600If wrong:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys3. Check the key entry itself
cat ~/.ssh/authorized_keys- Each key must be on one line (no line breaks in the middle).
- It should start with
ssh-ed25519orssh-rsa.
4. Check client is using the correct key
ssh -v username@server-ipLook for:
Offering public key: /home/you/.ssh/id_ed25519
Authentication succeeded (publickey)If you see “no mutual signature supported” or “no supported methods”, your key type might be unsupported or disabled.
C. “REMOTE HOST IDENTIFICATION HAS CHANGED!”
Error:
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!SSH stores server fingerprints in ~/.ssh/known_hosts.
This warning appears if:
- The server was rebuilt
- The IP now points to a different machine
- Or a real man-in-the-middle (rare, but possible)
If you know the server legitimately changed:
nano ~/.ssh/known_hosts
# or
ssh-keygen -R server-ipThen connect again and accept the new fingerprint.
If you’re not sure → double-check with the admin or cloud panel before continuing.
D. Problems with ssh-copy-id
Error:
ssh-copy-id: command not foundInstall OpenSSH client:
sudo apt install openssh-clientError: still asks for password after ssh-copy-id
- Fix permissions on the server:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys- Confirm your key is in that file:
grep "ssh-ed25519" ~/.ssh/authorized_keys- Make sure you’re connecting with the same user and same key you just copied.
E. Where to look in logs
On the server:
sudo journalctl -u ssh --since "1 hour ago"
# or
sudo less /var/log/auth.logSearch for:
sudo grep 'Failed password' /var/log/auth.log
sudo grep 'Accepted publickey' /var/log/auth.logThis tells you:
- Which usernames attackers try
- Whether your key login is working (
Accepted publickey)
7. Final recap
If you only remember this flow, you’re good:
- On the server: install and start OpenSSH server, open port 22.
- From Linux client:
ssh username@server-ip→ test password login. - Generate key:
ssh-keygen -t ed25519 - Copy key to server:
ssh-copy-id username@server-ip - Log in with key:
ssh username@server-ip - Harden later: disable password login, root SSH, add Fail2ban & firewall.
And when something breaks, use the SSH troubleshooting cheat sheet above to quickly see whether it’s:
- Service not running
- Port/firewall issue
- Wrong user / wrong key
- File permissions
- Or host key mismatch








