Skip to content

Instantly share code, notes, and snippets.

@wwwqr-000
Created January 23, 2026 22:49
Show Gist options
  • Select an option

  • Save wwwqr-000/d953619f5bde5f5b5279af52eb4cb509 to your computer and use it in GitHub Desktop.

Select an option

Save wwwqr-000/d953619f5bde5f5b5279af52eb4cb509 to your computer and use it in GitHub Desktop.
Keyfile auth on Linux for ssh
# We have two machines in this case, a client (Own machine) and a server.
# In this case, the client is a Linux system, just like the server machine.
#On the client: (You can change "server1-key" to a desired filename, just like "server1")
ssh-keygen -t ed25519 -f ~/.ssh/server1-key -C "server1"
ssh-copy-id -i ~/.ssh/server1-key.pub user@server-ip
#
#If that last ssh-copy didn't work, because you can't ssh already, ask the server owner to add your public key to "~/.ssh/authorized_keys" on the server machine.
#On the server:
sudo nano /etc/ssh/sshd_config
#
#Make sure these lines are like the following:
# PubkeyAuthentication yes
# PasswordAuthentication no
#To check if PasswordAuthentication is set to yes somewhere, execute the following command:
grep -Ri PasswordAuthentication /etc/ssh/sshd_config.d/
#If any file has that set to "yes", set it to "no"
#On the server:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
#
#On the server: (Before restarting, make sure you're sure you can login with the keyauth-file setup that we made. Remember: you can set PasswordAuthentication to "yes" as well, to allow both password and keyfile, do this to make sure it works before softblocking yourself from your server machine)
sudo systemctl restart sshd
#
#On the client:
ssh -i ~/.ssh/server1-key username@ip
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment