LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   ssh problem - Permission denied (publickey) (https://www.linuxquestions.org/questions/linux-security-4/ssh-problem-permission-denied-publickey-4175567964/)

neidorff 01-26-2016 04:24 PM

ssh problem - Permission denied (publickey)
 
I am setting an automatic backup up from my OpenSuse 13.2 linux desktop to my Raspberry Pi2 (with a large external drive) running raspbian (updated). I use static IP addresses. My desktop is 192.169.1.1 and the Pi is 192.168.1.20 .

Part of the configuration is to enable automatic ssh login to the pi for the backup user (named "bu"). I followed the directions, and it worked.
Then, I remembered that I had never changed the Pi's root password from the default value. So, I changed the root password. Now when I try to ssh to the Pi like this:
$ssh bu@192.168.1.20
Permission denied (publickey)
$

I also have my web server at 192.168.1.1 and I can ssh into that server just fine with:
$ssh mark@192.168.1.1
mark@web:~$
(no errors)

2 things:
#1: Why am I now getting this error? What does the root login have to do with ssh as a user?

#2: What do I have to do in order to get the ssh login to work?

Many thanks,

Mark

Habitual 01-26-2016 04:27 PM

what happens on
Code:

ssh root@192.168.1.20
?

Habitual 01-26-2016 04:30 PM

Quote:

Originally Posted by neidorff (Post 5487719)
Part of the configuration is to enable automatic ssh login to the pi for the backup user (named "bu"). I followed the directions, and it worked.
Then, I remembered that I had never changed the Pi's root password from the default value. So, I changed the root password.

One way is to create a rsa key for the bu user and use that.
You will need to get the key's pub contents into /home/bu/.ssh/authorized_keys on 192.168.1.20

neidorff 01-26-2016 04:52 PM

I tried:
Code:

$ssh root@192.168.1.20
permission deined (publickey)

In other words, same error. I did have this working before I changed the root password on "192.168 1.20".

Thanks,
Mark

sundialsvcs 01-26-2016 07:42 PM

Remember that permissions on the .ssh and some of its contents must be "just so," or they will be ignored.

Also be certain that you have an SSH-agent running.

michaelk 01-26-2016 08:23 PM

We might need some additional information as to what you actually changed.

There isn't a default root password. The default user (pi) has sudo privileges and you can add a root password via sudo. How did you add the bu user? Did you make any changes to the sshd_conf file? What other changes did you make to the Pi?

As suggested check .ssh directory and private file permissions on the client. Check the .ssh directory and public key file permissions on the Pi.

try:
ssh -vvv bu@192.168.1.20

This will add some debug messages that might provide a clue.

neidorff 01-28-2016 02:20 PM

Here is the very verbose output of:
$ssh -vvv bu@192.168.1.20

Code:

mark@mark:~/.ssh> ssh -vvv bu@192.168.1.20
OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.1.20 [192.168.1.20] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/mark/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /home/mark/.ssh/id_rsa type 1
debug1: identity file /home/mark/.ssh/id_rsa-cert type -1
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/mark/.ssh/id_dsa" as a RSA1 public key
debug1: identity file /home/mark/.ssh/id_dsa type -1
debug1: identity file /home/mark/.ssh/id_dsa-cert type -1
debug1: identity file /home/mark/.ssh/id_ecdsa type -1
debug1: identity file /home/mark/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/mark/.ssh/id_ed25519 type -1
debug1: identity file /home/mark/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4+deb7u2
debug1: match: OpenSSH_6.0p1 Debian-4+deb7u2 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "192.168.1.20" from file "/home/mark/.ssh/known_hosts"
debug3: load_hostkeys: found key type ECDSA in file /home/mark/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-ed25519,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se                                                                                   
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se                                                                                   
debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96                             
debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: setup hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: setup hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 8b:1d:46:b5:81:f6:84:25:14:d8:f6:7f:68:59:31:28 [MD5]
debug3: load_hostkeys: loading entries for host "192.168.1.20" from file "/home/mark/.ssh/known_hosts"
debug3: load_hostkeys: found key type ECDSA in file /home/mark/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug1: Host '192.168.1.20' is known and matches the ECDSA host key.
debug1: Found key in /home/mark/.ssh/known_hosts:2
debug1: ssh_ecdsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/mark/.ssh/id_rsa (0x7fe3cf86b710),
debug2: key: /home/mark/.ssh/id_dsa ((nil)),
debug2: key: /home/mark/.ssh/id_ecdsa ((nil)),
debug2: key: /home/mark/.ssh/id_ed25519 ((nil)),
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/mark/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/mark/.ssh/id_dsa
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug3: sign_and_send_pubkey: RSA 6d:d6:22:45:d5:d0:3d:67:04:03:73:8f:6f:26:34:4f [MD5]
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/mark/.ssh/id_ecdsa
debug3: no such identity: /home/mark/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/mark/.ssh/id_ed25519
debug3: no such identity: /home/mark/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).


Habitual 01-28-2016 02:42 PM

You'll need to explicitly use an ssh key, eg:
Code:

ssh -i /home/mark/.ssh/bu_key -vvv bu@192.168.1.20
but without the bu_key.pub contents in /home/bu/.ssh/authorized_keys on 192.168.1.20 it will never work.

And now boys and girls, we now know why we never disco from a server until ssh is thoroughly vetted
for use with ssh keys.

michaelk 01-28-2016 03:57 PM

Not necessary to explicitly specify a key with the -i option. The default key files are ~/.ssh/id.rsa, ~/.ssh/id.dsa. The SuSE box appears to be sending the id.rsa key but the pi is not responding.

As suggested did you copy the public key to the authorized_keys file on the pi and does it have the correct permissions?

neidorff 01-30-2016 10:40 AM

OK. So, I want to start over with this configuration.

I see .ssh directories in user home directories on each PC. I also see ssh and ssl directories in /etc on each PC. If I delete the .ssh directories in each user's home, and (leaving the config files) clean out the ssh and ssl directories on each PC, will that be a good point to start this over from?

Thanks,
Mark

Habitual 01-30-2016 12:44 PM

Quote:

Originally Posted by neidorff (Post 5490374)
OK. So, I want to start over with this configuration.

I see .ssh directories in user home directories on each PC. I also see ssh and ssl directories in /etc on each PC. If I delete the .ssh directories in each user's home, and (leaving the config files) clean out the ssh and ssl directories on each PC, will that be a good point to start this over from?

Thanks,
Mark

No!
You see .ssh directories on the server?

michaelk 01-30-2016 02:37 PM

I agree with Habitual. Except for posting the debug messages you really have not answered our questions.

Do not delete anything in /etc/ssh or /etc/ssl on any PC. I assume you turned off password authentication in the pi's sshd_config but what else did you change?

How did you create the keys? I assume you created the keys on the desktop. Did you create separate keys or are you using the same? Did you copy the correct public key to the Pi. What are the authorized_key file permissions on the pi? Both keys should be 600.

neidorff 02-05-2016 02:36 PM

Let me clarify my configuration. I see your confusion...

I am currently working with 3 computers.
1. My desktop PC, running OpenSuse 13.2 (ip: 192.168.1.1)
2. My mail/web server running debian lenny (yes, I know it is a very old version) (ip: 192.168.1.6)
3. The Pi, running raspbian from the NOOBS. The Pi will be a server for backups. (ip: 192.168.1.20)

I mention my mail/web server in this discussion because I upload the spam e-mail that I receive (into spamassassin) onto the mail/web server and the no password ssh into this server works.

I followed the steps on this page: http://www.linuxproblem.org/art_9.html to configure the no password ssh into the mail/web server. It works.

I then repeated the steps for ssh from my desktop to the Pi. It worked. Then I realized that I had never changed the root user password from the default (which was a really silly omission on my part.) So, I changed the password of root. I don't remember how I did that, probably through sudo, but it is changed. Once I changed the root password, I tried to ssh into the Pi and I get the errors that I have mentioned before. This stopped the show on the Pi, so I haven't changed anything else.

I checked the permissions on the ~/.ssh directory on my desktop.
Code:

mark@mark:~> ls -la .ssh
total 24
drwx------  2 mark vboxusers 4096 Feb  5 14:54 .
drwxr-xr-x 71 mark vboxusers 4096 Feb  5 14:54 ..
-rw-------  1 mark vboxusers 3243 Jan 21 13:27 id_rsa
-rw-------  1 mark vboxusers  743 Jan 21 13:27 id_rsa.pub
-rw-r--r--  1 mark vboxusers  789 Jan 14 17:52 known_hosts

From what you told me, they seem right to me.

On the Pi, there is no .ssh directory on either the pi or the bu (backup) user's home directory.

Thanks for your help,
Mark

Habitual 02-05-2016 03:09 PM

Mark:
Are you able to ssh into the RaspPI from any host?
If so, please copy contents of /home/mark/id_rsa.pub to /home/bu_user/.ssh/authorized_keys
using the system that can connect as an intermediate access point to the PI.

If /home/bu_user/.ssh does not exist on PI, create it and set the perms using

Code:

mkdir /home/bu_user/.ssh && chmod 700 /home/bu_user/.ssh
then copy /home/mark/id_rsa.pub contents into a new file at /home/bu_user/.ssh/authorized_keys
Code:

nano /home/bu_user/.ssh/authorized_keys
Fix the perms on /home/bu_user/.ssh/authorized_keys with
Code:

chmod 600 /home/bu_user/.ssh/authorized_keys
I've seen possible issues from ssh user@host if "user" doesn't have a passwd set.
If not, get to the PI and use
Code:

passwd bu_user
as root, then

Then try ssh bu_user@pi.ip
If there is no password on the /home/mark/id_rsa key you should get right in.

Hope that helps.

michaelk 02-05-2016 03:26 PM

By repeating the same steps you would of overwritten the original keys. If you created the web server keys first then new keys for the Pi I would of expected that you would fail trying to log back into the web server. Since you can not log into the Pi then it appears you recreated the keys a few times or created the keys first for the Pi then the web server.

You can use the same key pairs on multiple computers if desired or create the key with a different name. You can specify different keys in a ssh config file or use a ssh key agent to store them.


All times are GMT -5. The time now is 07:00 AM.