Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to connect to my CentOS server via SSH, but Permission denied error was shown.

  • RPI to Server with "ssh foo.bar.com" command -> FAILED ("Permission denied" was shown)
  • RPI to Server with "ssh-agent", "ssh-add" and "ssh foo.bar.com" commands -> SUCCEEDED
  • PC to Server with "ssh foo.bar.com" command -> SUCCEEDED

How can I connect to server with "ssh foo.bar.com" command?

Details are as follows.

Raspberry PI -> Server

I tried to connect to my CentOS server via SSH from my Raspberry PI (Raspbian wheezy). But Permission denied error was shown. How can I connect to my server?

d_komatsuda@raspberrypi ~ $ ssh -v foo.bar.com

Then I got following error (excerpt).

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/d_komatsuda/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Trying private key: /home/d_komatsuda/.ssh/id_dsa
debug1: Trying private key: /home/d_komatsuda/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Permissions are as follows:

d_komatsuda@raspberrypi /home $ ls -ld d_komatsuda
drwxr-xr-x 4 d_komatsuda d_komatsuda 4096 Oct 12 06:52 d_komatsuda
d_komatsuda@raspberrypi /home $ ls -ld d_komatsuda/.ssh
drwx------ 2 d_komatsuda d_komatsuda 4096 Oct 12 06:08 d_komatsuda/.ssh
d_komatsuda@raspberrypi /home $ ls -l d_komatsuda/.ssh
total 16
-rwx------ 1 d_komatsuda d_komatsuda  405 Oct 12 04:57 authorized_keys
-rw------- 1 d_komatsuda d_komatsuda 1743 May 25 18:39 id_rsa
-rwx------ 1 d_komatsuda d_komatsuda  405 Oct 12 04:55 id_rsa.pub
-rw-r--r-- 1 d_komatsuda d_komatsuda 1106 Oct 12 05:50 known_hosts

Why "Enter passphrase for .ssh/id_rsa:" isn't shown?

In addition there are authorized_keys and id_rsa.pub because I'd like to access from my PC via SSH.

Raspberry PI -> Server : With ssh-agent

I couldn't connect to my server in above way, but with ssh-agent, I could connect.

d_komatsuda@raspberrypi ~ $ ssh-agent bash
d_komatsuda@raspberrypi ~ $ ssh-add .ssh/id_rsa
Enter passphrase for .ssh/id_rsa:
Identity added: .ssh/id_rsa (.ssh/id_rsa)
d_komatsuda@raspberrypi ~ $ ssh -v foo.bar.com

Following messages was shown (excerpt).

debug1: Next authentication method: publickey
debug1: Offering RSA public key: .ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: Authentication succeeded (publickey).
Authenticated to foo.bar.com ([xxx.xxx.xxx.xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Last login: Sat Oct 12 20:49:30 2013 from xxxxxx.yyyyyy.jp

SAKURA Internet [Virtual Private Server SERVICE]

[d_komatsuda@www1447ui ~]$

Why could I connect to my server with ssh-agent, but couldn't without ssh-agent?

My PC (Cygwin) -> Server

From my Cygwin console, I can connect to my server correctly.

d_komatsuda@i7-975 ~
$ ssh -v foo.bar.com

Then I got following messages (excerpt).

debug1: Next authentication method: publickey
debug1: Trying private key: /home/d_komatsuda/.ssh/id_rsa
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/home/d_komatsuda/.ssh/id_rsa':
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to foo.bar.com ([xxx.xxx.xxx.xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Last login: Sat Oct 12 17:03:13 2013 from xxxxxx.yyyyyy.jp

SAKURA Internet [Virtual Private Server SERVICE]

[d_komatsuda@www1447ui ~]$

Please give me some advice.

Logs from server side

I got following logs (/var/log/secure) when I tried to connect to the server from the RPi and got "Permission denied" error.

Oct 12 21:36:30 www1447ui sshd[16829]: debug1: Forked child 16857.
Oct 12 21:36:30 www1447ui sshd[16857]: Set /proc/self/oom_score_adj to 0
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: rexec start in 7 out 7 newsock 7 pipe 9 sock 10
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: inetd sockets after dupping: 3, 3
Oct 12 21:36:30 www1447ui sshd[16857]: Connection from yyy.yyy.yyy.yyy port 57716
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: Client protocol version 2.0; client software version OpenSSH_6.0p1 Debian-4
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: match: OpenSSH_6.0p1 Debian-4 pat OpenSSH*
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: Enabling compatibility mode for protocol 2.0
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: Local version string SSH-2.0-OpenSSH_5.3
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: permanently_set_uid: 74/74
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: list_hostkey_types: ssh-rsa,ssh-dss
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEXINIT sent
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEXINIT received
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: kex: client->server aes128-ctr hmac-md5 none
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: kex: server->client aes128-ctr hmac-md5 none
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_NEWKEYS sent
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: expecting SSH2_MSG_NEWKEYS
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_NEWKEYS received
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: KEX done
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: userauth-request for user d_komatsuda service ssh-connection method none
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: attempt 0 failures 0
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: PAM: initializing for "d_komatsuda"
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: PAM: setting PAM_RHOST to "xxxxxx.yyyyyy.jp"
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: PAM: setting PAM_TTY to "ssh"
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: userauth-request for user d_komatsuda service ssh-connection method publickey
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: attempt 1 failures 0
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: test whether pkalg/pkblob are acceptable
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: temporarily_use_uid: 500/500 (e=0/0)
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: trying public key file /home/d_komatsuda/.ssh/authorized_keys
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: fd 4 clearing O_NONBLOCK
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: restore_uid: 0/0
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: temporarily_use_uid: 500/500 (e=0/0)
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: trying public key file /home/d_komatsuda/.ssh/authorized_keys2
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: restore_uid: 0/0
Oct 12 21:36:31 www1447ui sshd[16857]: Failed publickey for d_komatsuda from yyy.yyy.yyy.yyy port 57716 ssh2
Oct 12 21:36:31 www1447ui sshd[16858]: Connection closed by yyy.yyy.yyy.yyy
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: do_cleanup
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: do_cleanup
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: PAM: cleanup
share|improve this question
    
Add the logs from the server side (/var/log/auth.log) during the failed login attempts after you have set LogLevel DEBUG on the server configuration (/etc/ssh/sshd_config) and restarted it. –  dawud Oct 12 '13 at 12:31
    
@dawud Added the logs (server side). "Failed publickey for ..." means the pair of the public key and the private key is invalid? (But MD5 of id_rsa is same on RPi and my PC) –  Daiki Komatsuda Oct 12 '13 at 12:46
    
@lain Thank you for pointing them out. I read them. My question was certainly hobby question (not professional question)... I'll examine using Super User or U&L. –  Daiki Komatsuda Oct 12 '13 at 13:02
    
The error message: "Failed publickey for d_komatsuda" is the interesting bit there. –  dawud Oct 12 '13 at 13:21
    
@dawud I solved myself. I found this site (Japanese). According to it, id_rsa and id_rsa.pub in ~/.ssh must be pair. In my case, id_rsa.pub is the public key for the authentication between my PC and RPi. id_rsa is the private key for the authentication between {my PC or RPi} to my server. So they're not pair. I renamed id_rsa to id_rsa_vps and did ssh -i ~/.ssh/id_rsa_vps foo.bar.com, then I could connect to my server from RPi without ssh-agent! Thank you. –  Daiki Komatsuda Oct 12 '13 at 13:50
add comment

migrated from serverfault.com Oct 12 '13 at 17:15

This question came from our site for professional system and network administrators.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.