How to log in as non root user via SSH?
I just created my first Ubuntu droplet and supplied my public SSH key which is contained in
~/.ssh/id_rsa.pub on my local machine at the time I was creating my droplet. I can SSH into my machine as root just fine via the command
ssh root@remote_host where
remote_host is my droplet's IP address as given in the console. However, I would like to prohibit root logon to my droplet.
I created a new user by executing the commands
adduser newusername followed by
gpasswd -a newusername sudo to give the new user elevated privileges. I then manually copied over the contents of my public SSH key (from my local machine) following these instructions over to
$ mkdir .ssh $ chmod 700 .ssh $ cd .ssh $ vim authorized_keys
I then pasted in the public key and saved the file
$ chmod 600 authorized_keys $ exit # service ssh restart
When I tried to SSH in from my local machine using the command
ssh newusername@remote_host, I get the message
Permission denied (publickey). I even went back into the droplet and added the line AllowUsers newusername to the
/etc/ssh/sshd_config file but keep getting the same error.
UPDATE: I also tried running the following commands on my local machine, which is also running Ubuntu, but this did not work either:
$ eval `ssh-agent -s` $ ssh-add ~/.ssh/id_rsa