Steps
1. Generate a new key pair.
In you laptop/pc open up the terminal, the type :
ssh-keygen -t ed25519 -C "comment"
This will generate a key pair, a private one and a publc one. The file name you put with .pub
is the public key. It will ask for a file name and a passphrase and other stuff. Setup accordingly.
2. Copy the public key to the remote server.
cat ~/.ssh/key.pub | ssh username@192.168.1.69 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Change the path
and other stuff accordingly.
If this gives an error, which it might if you are using windows powershell, use this :
Get-Content $env:USERPROFILE\\.ssh\\key.pub | ssh username@192.168.1.69 "cat >> .ssh/authorized_keys"
This will copy your key.pub
file from /.ssh/
and append it to the ~/.ssh/authorized_keys
. Change the path accordingly.
3. Login using ssh key.
Run :
ssh username@192.168.1.69
OR :
ssh -i ".ssh/key" username@192.168.1.69
The key
is the "filename"
, provide path/to/file
if needed.
If it doesn’t asked for password and let you right in, that means it worked.