-
-
Notifications
You must be signed in to change notification settings - Fork 1
HOWTO devops ssh_keys
steveoro edited this page Jan 16, 2021
·
1 revision
SSH Key-based access allows to disable console login for all users except the ones holding a reference public key.
WARNING: obviously, loosing or removing the key file from the local machine will make the remote server inaccessible once that password access has been disabled. So proceed with extreme caution
Assuming no previous keys were generated, on localhost:
$ ssh-keygen -t rsa
- Enter file in which to save the key (
/home/username/.ssh/id_rsa
) - Enter a very long passphrase
- private key:
id_rsa
- public key:
id_rsa.pub
On your localhost:
$ cat ~/.ssh/id_rsa.pub
Copy and paste the resulting text into the form requesting the key.
From your localhost:
$ ssh-copy-id username@remote_host
From your localhost:
$ cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Test remote, password-less access from localhost:
$ ssh username@remote_host
On the remote server:
$ sudo vim /etc/ssh/sshd_config
...And edit setting:
PasswordAuthentication no
Save and close. Restart ssh service:
$ sudo service ssh restart