Installing an SSH key on a Debian server involves generating the key pair, transferring the public key, and configuring SSH for authentication. Here’s a step-by-step guide:
1. Generate the SSH Key Pair
On your local machine, generate an SSH key pair using the following command:
ssh-keygen -t rsa -b 4096
- You can also use
ed25519
for better security:
ssh-keygen -t ed25519
- Save the key in the default location (
~/.ssh/id_rsa
) or specify a custom path. - You may set a passphrase for extra security.
2. Copy the Public Key to the Debian Server
Use ssh-copy-id
to transfer your public key to the remote server:
ssh-copy-id user@your-debian-server-ip
If ssh-copy-id
is unavailable, manually copy the key:
cat ~/.ssh/id_rsa.pub | ssh user@your-debian-server-ip “mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys”
3. Verify SSH Key Authentication
Try logging in without a password:
ssh user@your-debian-server-ip
4. (Optional) Disable Password Authentication
For extra security, edit the SSH configuration file on the server:
sudo nano /etc/ssh/sshd_config
- Find and set:
PasswordAuthentication no
- Save and restart SSH:
sudo systemctl restart ssh