Ubuntu – ssh permission denied(public key)

ssh

I have just installed VirtualBox and Vagrant on my coputer and initialized a ubuntu/bento-16.04 box. I have added a new user beside vagrant user and I have generated and copied the public key on the server in a file named authorized_keys. I also disbaled the possibility to authenticate with a paswword.

The problem is that i can connect to the server only if a provide to the ssh command the full path to my private key (located on the C drive of my computer), under -i flag.

If a try to connect just with ssh -p 2222 lucian@localhost i got this message:
permission denied(public key)

Is there any way i cann connect by ssh without providing the full path to the private key located on my computer?

My impression is that the server does not know about the location of the private key.

I red the earlier threads related to this issue but i can figure out what am I suppose to do to make the ssh-agent provide to the server the private key automatically.

Thanks!

Best Answer

Without editing files, you can use ssh-add yourkeyfile, it won't survive a reboot though.

To configure it as a permanent setting you can create or edit the following file

nano /home/yourusername/.ssh/config

Add the following entry

Host serverIP/FQDN
IdentityFile /home/yourusername/.ssh/yourkeyfile (or other path)

Now every time you connect to that specific host it will use that file.

You can also add the port number and username in the above configuration so that you only need to type ssh remotehostname to connect.

To do that add

 User remote_username
 Port remote_port#