Environment:
Any Linux-based system
Access Required:
Local or remote shell (SSH) access
🔐 Step 1: Generate SSH Key Pair
Run the following command on your local machine (or wherever the key should be created):
ssh-keygen -t rsa -b 4096
-t rsa: Specifies RSA algorithm-b 4096: Sets key size to 4096 bits (recommended)
Follow the prompts:
- Choose the file location (press Enter to use default
~/.ssh/id_rsa) - Optionally set a passphrase
📁 Step 2: Set Up .ssh Directory on the Remote Server
SSH into the remote server and run:
mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
These commands:
- Create the
.sshfolder and file (if missing) - Set proper permissions (required for SSH to work correctly)
📝 Step 3: Copy Public Key to the Server
On your local machine, run:
ssh-copy-id username@remote_host
Or manually copy the contents of your public key file (~/.ssh/id_rsa.pub) to the authorized_keys file on the server.
✏️ Step 4: Manually Edit Authorized Keys
If needed, you can manually edit the key file:
vi ~/.ssh/authorized_keys
- Press
ito insert - Paste the public key (usually starts with
ssh-rsa) - Press
Esc, then type:wqand pressEnterto save and exit
✅ Step 5: Test SSH Access
From your local machine:
ssh username@remote_host
If successful, it should log in without prompting for a password, unless you added a passphrase (in which case, it’ll ask for that).
