NOTE: This is not a duplicate to the popular question. Why am I still getting a password prompt with ssh with public key authentication?
I had an original post but I did not get much answers helping me. I will try and explain my 3 day problem in thorough detail.
How I added the id_rsa.pub ssh key into my Ubuntu server:
What I did was I created it through my normal windows 10 computer through a git scm terminal (can be found here https://git-for-windows.github.io/). I had to use git because a normal cmd prompt in windows 10 would not work. I generated it through ssh-keygen which generated 2 keys for me, one id_rsa and one id_rsa.pub.
After that I went on my putty terminal, logged into my remote server and created a .ssh directory in my /home/superjohnny folder (my sudo user) and I made a folder within the .ssh folder called authorized_keys. I copied and pasted my id_rsa.pub key into the authorized_keys folder and then later added 600 permissions on it by doing chmod 600 .ssh/authorized_keys.
Once I did that I went into my /etc/ssh/sshd_config and added the following into my config settings:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
All these lines are also uncommented. I then did sudo service ssh restart and then I still get a password prompt when trying to log in. This has been going on for a week
The methods I have tried: I have used both threads that were discussed above to try and get an answer and I have also used my google search extensively. Here are the methods that I have used.
1. Putting the key on one line I have tried using in the git scm terminal on my computer the following command:
cat ~/.ssh/id_rsa.pub | awk '{print}' ORS=' '
The command above supposedly doesn't do anything because the key was already on one line when I copied it, it's just that the terminal couldn't fit the key. Here is the thread I have used to find that command. https://stackoverflow.com/questions/36818651/how-to-display-output-on-single-line
Using the wc command: Using this command:
wc ~/.ssh/authorized_keysI have gotten an output of:
1 3 398 /home/superjohnny/.ssh/authorized_keysChecking if my home directory is encrypted: I have used the following command:
ls -A /home/superjohnnyand I have gotten an output of:
.bash_history .bash_logout .bashrc .cache .profile .ssh .viminfoThere was no .encrypted folder to be found.
Going on debugging mode to check for extra information: While on a session I did the following command:
ssh -v superjohnny@myip
and got this as a result:
debug1: Found key in /home/superjohnny/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/superjohnny/.ssh/id_rsa
debug1: Trying private key: /home/superjohnny/.ssh/id_dsa
debug1: Trying private key: /home/superjohnny/.ssh/id_ecdsa
debug1: Trying private key: /home/superjohnny/.ssh/id_ed25519
debug1: Next authentication method: password
This must be a hint to something but looking through the web for awhile I couldn't find much about this problem, only found a thread about it here: https://askubuntu.com/questions/54670/passwordless-ssh-not-working And this thead just tells me to recreate the key file which I have done numerous times
Using grep command: Using the following command:
grep -v '^[[:space:]]*$' ~/.ssh/authorized_keys | wc -lI get a output of:
1Checking logs messages: Using the following command:
sudo vi /var/log/auth.logI have received a lot of errors all on the same day, the same exact error but I will only post a bit of it:
Apr 25 04:14:01 ramnode CRON[977]: pam_unix(cron:session): session closed for user root Apr 25 04:54:01 ramnode CRON[1076]: pam_env(cron:session): Unable to open env file: /etc/default/locale: No such file or directoryI have not received any other messages in any other days other than April 25th.
Going on debugging mode with sshd:
Doing
/usr/sbin/sshd -d
gives me an output of:
debug1: sshd version OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: could not open key file '/etc/ssh/ssh_host_rsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_rsa_key
debug1: could not open key file '/etc/ssh/ssh_host_dsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_dsa_key
debug1: could not open key file '/etc/ssh/ssh_host_ecdsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
debug1: could not open key file '/etc/ssh/ssh_host_ed25519_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_ed25519_key
debug1: setgroups() failed: Operation not permitted
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
However adding sudo in front of the command likeso:
sudo /usr/sbin/sshd -d
gives me an output of:
debug1: sshd version OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type ECDSA
debug1: private host key: #2 type 3 ECDSA
debug1: private host key: #3 type 4 ED25519
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
Set /proc/self/oom_score_adj from -800 to -1000
Trying to see if home directory permissions had to be smaller: I tried to change the home directory permissions because I thought that the permissions might not allowed for the .ssh directory to work. I used the following command:
chmod 755 ~/but that did nothing at all when I restarted my terminal with sudo service ssh restart and then when I logged back into another terminal it still prompted me with a password.
Trying to disable Password I have tried to disable the password and not logging out of my secession so I can change it if it doesn't work. I did this by going into the
/etc/ssh/sshd_configbut when I went on to a new terminal screen I get the following error:
Disconnected: No supported authentication methods avaliable(server sent: publickey
The /var/log/auth.log messages that I had when trying to log in with password disabled so the system would try and use ssh keys was this:
May 1 09:02:00 ramnode sshd[16905]: error: Received disconnect from 64.121.77.168: 14: No supported authentication methods available [preauth]
May 1 09:02:13 ramnode sudo: superjohnny : TTY=pts/1 ; PWD=/home/superjohnny ; USER=root ; COMMAND=/usr/bin/vi /var/log/auth.log
May 1 09:02:13 ramnode sudo: pam_unix(sudo:session): session opened for user root by superjohnny(uid=0)
