You log in to a Linux server over SSH by running ssh username@server-ip from an SSH client, then proving who you are with either a password or a private key. This guide covers both methods on Windows, macOS and Linux, plus how to set up key-based login, fix the most common connection errors and lock down the server once you can reach it.
Step 1 – We need to use ssh client to be installed in a laptop.
- putty
- gitbash
- SuperPuTTY
- MobaXterm
- mRemoteNG
- https://www.devopsschool.com/blog/list-of-free-tools-for-tabbed-multiple-linux-ssh-putty-sessions/
Code language: JavaScript (javascript)
Step 2 – SSH login method
- Username & password OR
- Username & pvt key (pem for ssh or ppk for putty)
Step 3 – SSH login using server IP & Username & password
putty:
- server ip - 192.168.1.16
- username - root
- password - rajesh123
gitbash & Mac:
- server ip
- username
- password
$ ssh root@192.168.1.16
Step 4 – SSH login using server IP & Username & pvt key
putty using ppk file:
follow step 5 & step 6 from - https://www.devopsschool.com/blog/how-to-login-linux-server-of-aws-from-windows-using-putty/
gitbash using pem file & Mac:
$ ssh -i key.pem root@192.168.1.16
Code language: JavaScript (javascript)
Reference
- https://www.devopsschool.com/blog/how-to-configure-and-access-linux-vms-using-virtualbox-for-local-lab-and-practice/
- https://www.devopsschool.com/blog/how-to-login-linux-server-of-aws-from-windows-using-putty/
- Download gitbash for windows – https://git-scm.com/downloads
How an SSH login works
SSH (Secure Shell) has two parts. The client runs on your laptop: ssh, PuTTY, MobaXterm and so on. The server is the sshd daemon on the Linux machine, which listens on TCP port 22 by default. The client opens an encrypted connection, checks the server's host key, and then logs you in with one of the authentication methods the server allows.
| Method | What you need | Typical use |
|---|---|---|
| Password | Username and that user's password | Local lab VMs, first-time setup |
| Public key | Username and a private key file (OpenSSH format such as .pem, or .ppk for PuTTY) | Cloud servers (AWS, Azure, GCP) and production |
Windows 10, Windows 11 and current Windows Server releases come with the OpenSSH client, so the ssh commands in this guide work in PowerShell or Command Prompt as well as in Git Bash, macOS Terminal and Linux shells.
Check the server side before you connect
Most failed logins happen because the server isn't reachable or sshd isn't running. If you have console access to the server (for example the VirtualBox window or a cloud serial console), check these first.
# Find the server's IP address
ip -4 addr show
# Check that the SSH daemon is running
# (the service is called 'sshd' on RHEL/CentOS/Fedora/Amazon Linux, 'ssh' on Debian/Ubuntu)
sudo systemctl status sshd # or: sudo systemctl status ssh
# Confirm something is listening on port 22
sudo ss -tlnp | grep ':22'
# Install and start the server if it is missing
sudo apt install -y openssh-server && sudo systemctl enable --now ssh # Debian/Ubuntu
sudo dnf install -y openssh-server && sudo systemctl enable --now sshd # RHEL familyCode language: PHP (php)
On cloud servers you also need a security group or firewall rule that allows inbound TCP 22 from your public IP. Inside the server, firewalld or ufw can block the port too. Open it with sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload or sudo ufw allow OpenSSH.
Log in with a username and password
ssh devops@192.168.1.16
# If the server listens on a non-default port
ssh -p 2222 devops@192.168.1.16Code language: PHP (php)
The first time you connect to a server, the client asks you to confirm its host key:
The authenticity of host '192.168.1.16 (192.168.1.16)' can't be established.
ED25519 key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.1.16' (ED25519) to the list of known hosts.
devops@192.168.1.16's password:Code language: PHP (php)
Type yes and the fingerprint is saved to ~/.ssh/known_hosts. Then enter the password. Nothing appears on screen while you type it, and that's normal. When you see a prompt such as [devops@server ~]$, you're logged in. Type exit or press Ctrl+D to disconnect.
Note: On production systems, compare the fingerprint with the real one (run ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub on the server console) before you type yes. Confirming the host key is what protects you from a man-in-the-middle attack.
Log in with a private key
OpenSSH won't use a private key file that other users can read. Lock down its permissions first, then pass the key with -i.
# macOS, Linux, Git Bash
chmod 400 ~/Downloads/key.pem
ssh -i ~/Downloads/key.pem ec2-user@203.0.113.10Code language: PHP (php)
# Windows PowerShell (built-in OpenSSH): remove inherited permissions and grant read only to yourself
icacls .\key.pem /inheritance:r
icacls .\key.pem /grant:r "$($env:USERNAME):(R)"
ssh -i .\key.pem ec2-user@203.0.113.10Code language: PHP (php)
Cloud images usually turn off direct root login and create a default user instead, so use the right username for the image:
| Image | Default username |
|---|---|
| Amazon Linux, RHEL on AWS | ec2-user |
| Ubuntu | ubuntu |
| Debian | admin |
| CentOS Stream / Rocky / AlmaLinux (varies by publisher) | centos, rocky, ec2-user |
PuTTY needs the key in .ppk format. The PuTTY login guide shows how to convert it with PuTTYgen. You can also convert in the other direction, from .ppk to OpenSSH format, so the same key works with the ssh command: puttygen key.ppk -O private-openssh -o key.pem.
Create your own key pair and save connection details
If you can already log in with a password, switch to key-based login. It's more secure and you won't need to type the password each time.
- On your laptop, generate a key pair:
ssh-keygen -t ed25519 -C "you@laptop". Accept the default path (~/.ssh/id_ed25519) and set a passphrase. - Copy the public key to the server:
ssh-copy-id devops@192.168.1.16. On Windows, wheressh-copy-idisn't available, run:type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh devops@192.168.1.16 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys". - Test it:
ssh devops@192.168.1.16. You should be asked for the key passphrase (if you set one), not the account password.
Save frequently used servers in ~/.ssh/config (on Windows, C:\Users\<you>\.ssh\config). After that, ssh lab is all you need to type:
Host lab
HostName 192.168.1.16
User devops
Port 22
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yesCode language: JavaScript (javascript)
Corrections to the steps above
- Built-in client on Windows: Git Bash still works, but it isn't required. Windows 10 and 11 ship with the OpenSSH
sshcommand. - Key permissions:
ssh -i key.pemfails withUNPROTECTED PRIVATE KEY FILEunless you first runchmod 400 key.pem(or theicaclscommands on Windows). - Root user: many distributions and almost all cloud images block root login over SSH. Log in as a normal user such as
ec2-userorubuntu, then usesudo. - Passwords in examples: the example above shows a real-looking root password. Never share or reuse credentials like this. Use a strong unique password, or better, key-based login.
- Missing details: use
-p PORTwhen the server doesn't listen on port 22, and expect the host key confirmation prompt the first time you connect.
Common SSH errors and fixes
| Error | Likely cause | Fix |
|---|---|---|
Connection timed out | Wrong IP, server down, or a firewall/security group blocking port 22 | Check the IP, the cloud inbound rules and firewalld/ufw |
Connection refused | sshd not running or listening on another port | sudo systemctl start sshd; check Port in /etc/ssh/sshd_config |
Permission denied (publickey) | Wrong username, wrong key, or password login disabled | Use the image's default user and the correct -i key; run ssh -v to see which keys are tried |
WARNING: UNPROTECTED PRIVATE KEY FILE! | Key file can be read by other users | chmod 400 key.pem or fix the ACL with icacls |
Load key "key.ppk": invalid format | Passing a PuTTY key to OpenSSH | Convert with puttygen key.ppk -O private-openssh -o key.pem |
REMOTE HOST IDENTIFICATION HAS CHANGED! | Server was rebuilt or the IP was reused (or a real attack) | Verify the new fingerprint, then ssh-keygen -R 192.168.1.16 |
Too many authentication failures | SSH agent offers too many keys before the right one | Add -o IdentitiesOnly=yes along with -i |
Note: ssh -v user@host (or -vvv for more detail) prints each stage of the connection and authentication. It's the fastest way to see where a login fails.
Harden SSH once you can log in
Once key login works for a user with sudo rights, turn off root and password logins in /etc/ssh/sshd_config. Also check for drop-in files under /etc/ssh/sshd_config.d/. sshd uses the first value it reads for each setting, so a drop-in (for example one created by cloud-init) can override your change.
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
# Validate the configuration, then reload (service is 'ssh' on Debian/Ubuntu)
sudo sshd -t && sudo systemctl reload sshdCode language: PHP (php)
Note: Keep your current session open and test a new login in a second terminal before you close it. If the new config locks you out, you can still fix it from the open session.
Frequently asked questions
What is the basic command to SSH into a Linux server?
Run ssh username@server-ip, for example ssh devops@192.168.1.16. Add -i keyfile to log in with a private key and -p port if the server doesn't use port 22.
Do I need PuTTY or Git Bash to use SSH on Windows?
No. Windows 10 and 11 include the OpenSSH client, so ssh works directly in PowerShell or Command Prompt. PuTTY and MobaXterm are optional graphical alternatives.
Why do I get Permission denied (publickey) on an AWS server?
The usual causes are the wrong username (use ec2-user for Amazon Linux or ubuntu for Ubuntu, not root) or the wrong key file. Run ssh -v to see which key is being offered.
What is the difference between a .pem and a .ppk key?
Both can hold the same private key. .pem is the OpenSSH-compatible format used by the ssh command, and .ppk is PuTTY's own format. PuTTYgen converts between them.
How do I fix 'UNPROTECTED PRIVATE KEY FILE'?
Make the key readable only by you. Run chmod 400 key.pem on macOS, Linux or Git Bash, or remove inherited permissions with icacls on Windows, then connect again.
Related tutorials
- How to Login to Linux Server using Putty?
- More Linux tutorials
- Pomerium Tutorial: Complete End-to-End Guide to Zero-Trust Access, Identity-Aware Proxy, SSO, Kubernetes, SSH and Production Deployment
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals
The tutorial would benefit from discussing SSH as an operational access mechanism rather than just a connectivity tool. In production environments, teams typically avoid password-based logins altogether, disable direct root access, standardize on Ed25519 keys, and manage authorized keys through configuration management or IAM-backed solutions. It is also useful to mention host fingerprint verification, SSH client configuration (
~/.ssh/config) for managing large server fleets, session auditing, and short-lived credentials to reduce the blast radius of compromised keys. These practices become increasingly important as organizations move from managing a handful of servers to operating hundreds of ephemeral cloud instances and Kubernetes worker nodes.