LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 09-12-2012, 09:28 PM   #1
tquang
Member
 
Registered: Jul 2010
Posts: 44

Rep: Reputation: 0
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?

Last edited by tquang; 09-12-2012 at 09:34 PM.
 
Old 09-12-2012, 09:36 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.

Last edited by jschiwal; 09-12-2012 at 09:40 PM.
 
1 members found this post helpful.
Old 09-12-2012, 09:47 PM   #3
kfritz
Member
 
Registered: Aug 2006
Distribution: Slackware, OpenBSD, CentOS, Ubuntu
Posts: 99

Rep: Reputation: 31
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.
 
1 members found this post helpful.
Old 09-12-2012, 10:02 PM   #4
tquang
Member
 
Registered: Jul 2010
Posts: 44

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
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 View Post
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)

Last edited by tquang; 09-12-2012 at 10:05 PM.
 
Old 09-13-2012, 12:11 AM   #5
tquang
Member
 
Registered: Jul 2010
Posts: 44

Original Poster
Rep: Reputation: 0
Hi, exactly, this is my mistake. I can solved by:

chmod 700 /home/alibaba/.ssh

Then, in sshd_config, set AllowUsers for user
 
Old 09-13-2012, 09:27 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by tquang View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH KEY with root user doesn't work Lucas Rey Linux - Security 7 08-06-2012 09:06 AM
[SOLVED] Using a public SSH key on more than one user Mad-Halfling Linux - Security 16 05-16-2012 08:14 AM
[SOLVED] ssh public key login doesn't work as root user confconf Fedora 6 04-06-2011 03:08 PM
SSH-key for apache user? GaijinPunch Linux - Software 4 02-02-2011 04:48 AM
Key based authentication only for root for SSH the_gripmaster Linux - Security 4 04-18-2009 05:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration