LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   SSH by key for non-root user (https://www.linuxquestions.org/questions/linux-security-4/ssh-by-key-for-non-root-user-4175426975/)

tquang 09-12-2012 09:28 PM

SSH by key for non-root user
 
Hello all,

I have got 3 ssh public key:
_2 for root user
_1 for non-root user alibaba

Previously, all 3 publickey has been created and I just copy them to server.

With 2 key for ssh user, I just mix them in /root/.ssh/authorized_keys, absolutely it's work fine
ssh -i /path/private.key root@server
Quote:

Originally Posted by /root/.ssh/authorized_keys
#Root key for user 1
ABCXXXXX

#Root key for user 2
DEFYYYYY

Then, at /home/alibaba/.ssh, I created authorized_keys file with content of non-root user public key. However, it's not work
Example in this case is username alibaba
ssh -i /path/private.key alibaba@server

Of course, I chown by command: chown -R alibaba:alibaba /home/alibaba/.ssh/
Also, I chmod by command: chmod -R 400 /home/alibaba/.ssh/

How can I config for ssh can work well?

jschiwal 09-12-2012 09:36 PM

The public key you added is to allow incoming SSH connections on your home computer. Is that what you are trying to do?

Also check the permissions of /home/alibaba.

Use "ssh-vv" for debugging information.
If your home computer doesn't have an Internet address, you need to forward port 20 to your computer at the router.

kfritz 09-12-2012 09:47 PM

sshd is very fussy about permissions. Make sure /home/alibaba and /home/alibaba/.ssh are not writeable by others. Look at the man page for sshd and read the section near the end about authorized_users file.

tquang 09-12-2012 10:02 PM

Quote:

Originally Posted by jschiwal (Post 4779023)
The public key you added is to allow incoming SSH connections on your home computer. Is that what you are trying to do?

Also check the permissions of /home/alibaba.

Use "ssh-vv" for debugging information.
If your home computer doesn't have an Internet address, you need to forward port 20 to your computer at the router.

This is server with public IP, it place at DC and SSH port open. And below output from command: ssh -vv -i /LOCAL/PATH/STORE/PRIVATE_rsa kiemtra@IP.SERVER
Code:

OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to IP.SERVER [IP.SERVER] port 22.
debug1: Connection established.
debug1: identity file /LOCAL/PATH/STORE/PRIVATE_rsa type -1
debug1: identity file /LOCAL/PATH/STORE/PRIVATE_rsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa,ssh-dss-cert-v01@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-dss
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,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: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
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,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,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: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 130/256
debug2: bits set: 499/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 40:28:c4:c3:a1:bb:ba:e9:ae:f3:ab:0f:11:6a:56:c7
debug1: Host 'IP.SERVER' is known and matches the RSA host key.
debug1: Found key in /Users/tquang/.ssh/known_hosts:2
debug2: bits set: 516/1024
debug1: ssh_rsa_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: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /LOCAL/PATH/STORE/PRIVATE_rsa (0x7fa11041e4c0)
debug2: key: /LOCAL/PATH/STORE/PRIVATE_rsa (0x0)
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /LOCAL/PATH/STORE/PRIVATE_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Trying private key: /LOCAL/PATH/STORE/PRIVATE_rsa
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: read PEM private key done: type RSA
Identity added: /LOCAL/PATH/STORE/PRIVATE_rsa (/LOCAL/PATH/STORE/PRIVATE_rsa)
debug1: read PEM private key done: type RSA
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug2: we did not send a packet, disable method

=====
Quote:

Originally Posted by kfritz (Post 4779025)
sshd is very fussy about permissions. Make sure /home/alibaba and /home/alibaba/.ssh are not writeable by others. Look at the man page for sshd and read the section near the end about authorized_users file.

I chmod from 755 to 700 for /home/alibaba
With /home/alibaba/.ssh I chmod 400 (include all file in here)

tquang 09-13-2012 12:11 AM

Hi, exactly, this is my mistake. I can solved by:

chmod 700 /home/alibaba/.ssh

Then, in sshd_config, set AllowUsers for user

unSpawn 09-13-2012 09:27 AM

Quote:

Originally Posted by tquang (Post 4779030)
This is server with public IP, it place at DC and SSH port open.

...then you should not allow root to log in over ssh in the first place.


All times are GMT -5. The time now is 07:09 PM.