Vagrant : Create new user and force the use of ssh keys for accessing the server

471 views Asked by At

I try to enforce the use of SSH keys in order to access the server (I disabled password-based login).

I use "ubuntu/trusty64" for my vagrant. After the first boot of my VM, I created another user "gwendal" and I added him to the sudo group.

Here are the steps I followed :

  • [on my local computer] : cd ~/.ssh then ssh-keygen -t rsa -b 4096 -C [email protected] -f id_gwendal and I finally copied the content of id_gwendal.pub

  • [on my guest] : I switch from vagrant to gwendal user and I pasted the public key to ~/.ssh/authorized_keys

So I was supposed to be able to log in but I always have this message : Permission denied (publickey).

I tried :

1

There are 1 answers

0
Adrien G On

Thanks to the suggestion of Remus Rusanu I find the error.

When I check the last logs with tail -500 /var/log/auth.log | grep 'sshd' I noticed this:

error: Could not load host key: /etc/ssh/ssh_host_ed25519_key

So I checked the sshd_config file and there was this line (I didn't add myself):

# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

So I simply commented the last line and I could access my server with my public key.