🎯 Objective
Configure SSH authentication in Linux to securely allow users to access a server remotely.
SSH authentication ensures that only authorized users can connect to the system.
🔐 What is SSH?
SSH (Secure Shell) is a protocol used to securely connect to remote systems over a network.
It provides:
Example connection:
ssh user@server-ipExample:
ssh devops@192.168.1.10🔑 Types of SSH Authentication
Linux supports two common authentication methods:
Key-based authentication is more secure and commonly used in DevOps environments.
🛠️ Step 1: Generate SSH Key Pair
Generate an SSH key on the client machine:
ssh-keygenExample output:
Generating public/private rsa key pair.Files created:
~/.ssh/id_rsa
~/.ssh/id_rsa.pub📤 Step 2: Copy Public Key to Server
Use the following command:
ssh-copy-id user@server-ipExample:
ssh-copy-id devops@192.168.1.10This copies the public key to:
/home/user/.ssh/authorized_keys🔍 Step 3: Test SSH Login
Now login without a password:
ssh user@server-ipExample:
ssh devops@192.168.1.10⚙️ Step 4: Configure SSH Server
Edit the SSH configuration file:
sudo nano /etc/ssh/sshd_configImportant settings:
PasswordAuthentication no
PubkeyAuthentication yes
PermitRootLogin noRestart SSH service:
sudo systemctl restart sshd🔍 Step 5: Verify SSH Service
Check SSH service status:
sudo systemctl status sshd