authentication
Server Access: Set Up SSH Key Authentication
2 min read
#authenticationServer Access: Set Up SSH Key Authentication
How to Access Server via SSH and Set Up SSH Key for Passwordless Authentication
Without setting up SSH Key, it will ask for a password each time we try to access the server.
Enhance security and convenience by establishing passwordless SSH logins using SSH key authentication. This guide explains the process of generating a key pair on your local machine, copying the public key to your server, and configuring your server to accept it.
Prerequisites
- A local machine (Windows, macOS, or Linux) with an SSH client installed.
- An SSH server running on your remote server/VPS.
- Access to both your local machine and server (SSH login credentials for the server).
To Get Access via SSH
- Syntax:
ssh -p PORT USERNAME@HOSTIP
- Example:
ssh -p 21350 root@216.32.44.12
Note
Run the commands below on your local machine, not on your VPS or remote server.
Generate SSH Key
ssh-keygen -f C:\Users\R/.ssh/my_key -t rsa -b 4096
Copy SSH Public Key to Remote Server (Not for Windows)
- Syntax:
ssh-copy-id -p PORT -i ~/.ssh/keyname.pub USERNAME@HOSTIP
- Example:
ssh-copy-id -p 21350 -i ~/.ssh/id_rsa.pub u27653@216.32.44.12
Copy Public Key to Remote Server (for Windows)
-
Make sure you have a
.ssh
folder on the remote server.- Syntax:
ssh -P PORT USERNAME@HOSTIP "mkdir /home/USERNAME/.ssh"
- Example:
ssh -P 21350 u27653@216.32.44.12 "mkdir /home/u27653/.ssh"
- Syntax:
-
Copy the public key.
- Syntax:
scp -P PORT SSH_PUBLIC_KEY_PATH USERNAME@HOSTIP:/home/USERNAME/.ssh/authorized_keys
- Example:
scp -P 21350 C:\Users\R/.ssh\id_rsa.pub u27653@216.32.44.12:/home/u27653/.ssh/authorized_keys
- Syntax: