Ads 468x60px

วันจันทร์ที่ 10 ตุลาคม พ.ศ. 2554

ปัญหาการใช้ SSH Public Key Authentication บน Solaris

ปัญหาการใช้ SSH Public Key Authentication บน Solaris
พยายามคอนฟิก Public Key Authentication เพื่อ login เข้าสู่เครื่องที่ติดตั้ง Solaris อยู่นาน ก็ไม่สามารถทำได้ แต่ในที่สุดก็สามารถหาปัญหาได้ เลยมาแชร์ประสบการณ์เผื่อจะเป็นประโยชน์

ทดสอบปัญหา

เริ่มต้นเพิ่ม user บนเครื่องที่ติดตั้ง Solaris 10 สมมติว่าชื่อ user1
[root@solaris ~]# useradd user1
[root@solaris ~]# id user1
uid=502(user1) gid=1(other) groups=1(other)
แก้ไข home ของ user1 ให้อยู่ใน /export/home/ และสร้างไดเร็คทอรี
[root@solaris ~]# cat /etc/passwd
...
user1:x:502:1::/export/home/user1:/bin/sh
[root@solaris ~]# cd /export/home
[root@solaris home]# mkdir user1
[root@solaris home]# chown user1 user1/
[root@solaris home]# su - user1
[user1@solaris ~]$ pwd
/export/home/user1
ต้องการให้ admin1 จากเครื่องที่ติดตั้ง linux สามารถ ssh ด้วย public key authentication เป็น user1 บนเครื่อง Solaris ได้
สร้าง public, private key ของ admin1
[admin1@linux ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/admin1/.ssh/id_rsa):
Created directory '/home/admin1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/admin1/.ssh/id_rsa.
Your public key has been saved in /home/admin1/.ssh/id_rsa.pub.
[admin1@linux ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtMbbgeFnn6vEo3IAVh... admin1@linux
copy ไฟล์ id_rsa.pub ของ admin1 ไปใส่ไว้ในไฟล์ authorized_keys ของ user1 บนเครื่อง Solaris
[user1@solaris ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtMbbgeFnn6vEo3IAVh... admin1@linux
ทดสอบ ssh จากเครื่อง linux
[admin1@linux ~]$ ssh -l user1 solaris
The authenticity of host 'solaris (192.168.1.2)' can't be established.
RSA key fingerprint is ...
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'solaris' (RSA) to the list of known hosts.
Password:
ขึ้นให้ใส่ password ไม่สามารถ login ด้วย public key authentication ได้

วิธีการแก้ไขปัญหา

หลังจากพยายามอยู่นาน ก็พบว่า ssh จะตรวจสอบสถานะ password ของผู้ใช้ด้วย ซึ่งถ้าดูในไฟล์ /etc/shadow จะเห็นว่า user1 จะถูก lock อยู่
[root@solaris ~]# cat /etc/shadow
...
user1:*LK*:::::::
ฟิลด์ที่สองในไฟล์ /etc/shadow คือ encrypted password คำอธิบายจาก man ของ shadow คือ
# man shadow
...
     password        An encrypted password for the user generated
                     by crypt(3C), a lock string to indicate that
                     the login is not accessible, or  no  string,
                     which  shows  that  there is no password for
                     the login.
                     The lock string is defined as  *LK*  in  the
                     first four characters of the password field.
...
การแก้ไขคือ ลบตัวอักษร LK ออก เช่นให้เหลือแต่เครื่องหมาย *
[root@solaris ~]# cat /etc/shadow
...
user1:*:::::::
ทดสอบ ssh จากเครื่อง linux อีกครั้ง ก็จะได้ตามที่ต้องการ
[admin1@linux ~]$ ssh -l user1 solaris
[user1@solaris ~]$

0 ความคิดเห็น:

แสดงความคิดเห็น

Blogger templates