Tool Logo
authentication

Server Access: Set Up SSH Key Authentication

Server Access: Set Up SSH Key Authentication
2 min read
#authentication

Server 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

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 [email protected]

Copy Public Key to Remote Server (for Windows)

  1. 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 [email protected] "mkdir /home/u27653/.ssh"
  2. 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 [email protected]:/home/u27653/.ssh/authorized_keys