Use Only Key File to Login Linux Server
Beginner guide for SSH keyfile login
This is a simple guide only for Linux beginners, showing the steps to use only key file to login Linux server and disable password login.
- Assume that you are now logged as
root
adduser ariel
usermod -aG sudo ariel
nano /etc/ssh/sshd_config
- Modify the following:
PasswordAuthentication no
PubkeyAuthentication yes
Note: If you have any.conf
file in/etc/ssh/sshd_config.d/
, which has any content ofPasswordAuthentication yes
, you can either change the value tono
or simply delete the conf file(s). - Generate key file (for the prompts just hit enter)
su - ariel
cd ~/.ssh
ssh-keygen -t rsa
- Copy publickey
cat id_rsa.pub >> authorized_keys
- Save the privatekey to local
cat id_rsa
Copy the content and paste it to your_key_name.pem
in your local computer
- Restart sshd of your server
systemctl restart sshd
- On your local, change permission
chmod 400 /your/key/path/your_key_name.pem
- Login with key file
ssh -i /your/key/path/your_key_name.pem ariel@your-server-ip
Copyright statement: Unless otherwise stated, all articles on this blog adopt the CC BY-NC-SA 4.0 license agreement. For non-commercial reprints and citations, please indicate the author: Henry, and original article URL. For commercial reprints, please contact the author for authorization.