Passwordless SSH using Private/Public Keys

This guide explains how to set up private/public key authentication for passwordless SSH, (specifically tailored for Debian systems.)

Step 1: Generate Key Pair

On your local machine, generate an RSA key pair:

ssh-keygen -t rsa -b 4096

Step 2: Transfer the Public Key to the Debian Server

Install ssh-copy-id on your local machine if needed (part of openssh-client):

sudo apt update && sudo apt install openssh-client -y

Transfer the public key:

ssh-copy-id user@server

Manual Alternative:

  1. Log into the server:
ssh user@debian_server
  1. Create the .ssh directory if it doesn’t exist:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
  1. Copy the contents of ~/.ssh/id_rsa.pub from your local machine into ~/.ssh/authorized_keys on the server.
  2. Set permissions:
chmod 600 ~/.ssh/authorized_keys

Step 3: Configure the Debian Server

Ensure the SSH server is installed and running:

sudo apt install openssh-server -y
sudo systemctl enable ssh
sudo systemctl start ssh

Verify /etc/ssh/sshd_config allows key-based authentication (default is fine):

sudo systemctl restart ssh

Step 4: Test Passwordless Login

From your local machine:

ssh user@server

Notes


Caponato's Samba notebook. Start here or else Main menu