- 論壇徽章:
- 3
|
我 安裝系統(tǒng)后 都會創(chuàng)建一個(gè) 用戶 加到wheel組 然后在這個(gè)用戶HOME目錄下創(chuàng)建.ssh目錄,上傳自己的公鑰文件進(jìn)去,添加或追加到authorized_keys文件里。
以下是網(wǎng)上找的資料,加自己的筆記
-------------------------------------------------
SSH2密鑰方式登錄驗(yàn)證的設(shè)置方法:
意思是用private/public key的方式進(jìn)行登錄驗(yàn)證,而不是輸入真正的用戶UNIX下的密碼。
key方式各個(gè)客戶端有點(diǎn)不兼容,但是服務(wù)器端是一樣的。一般應(yīng)當(dāng)使用客戶端生成用戶key,然后把public key弄到服務(wù)器上。如果是服務(wù)器上是OpenSSH,目錄是 .ssh,如果是SSH2,目錄是.ssh2。
Windows里面推薦使用SSH Secure Shell Client,比較兼容。利用SSH Secure Shell Client生成user key,然后用upload的選項(xiàng)上載到服務(wù)器上(前提是已經(jīng)登錄到服務(wù)器上),注意把.ssh2的目標(biāo)目錄改為.ssh(針對OpenSSH的服務(wù)器,如果服務(wù)器是SSH2,什么都不用改)。
.ssh目錄只需留xxx.pub文件
上載以后在.ssh的目錄里面執(zhí)行
ssh-keygen -X -f xxx.pub >> authorized_keys
xxx.pub是你的公鑰的文件名,就是剛剛被ssh client上載上去的那個(gè)。
然后就可以用key pair的方式登錄了。如果直接用root用戶登錄,記得看看
sshd_config
里面的 PermetRootLogin 選項(xiàng)改成 without-password
就是說禁止root用密碼的方式遠(yuǎn)程登錄,只能使用key pair。
最好sshd_config改為:
sshd_config
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes 改這個(gè)如下,禁止passwd登陸
PasswordAuthentication no
PermitEmptyPasswords no 禁止 空密碼登陸
#Protocol 2,1 原本的,改為下面的. 只準(zhǔn)ssh2的key登陸。
Protocol 2
同時(shí)也要把這句設(shè)為no
# Change to no to disable PAM authentication
ChallengeResponseAuthentication no
如果這句不設(shè)為no的話,用SSH Secure Shell Client還是可以用密碼登錄的。
但用putty、SecureCRT這時(shí)就不能用密碼登錄了。
===================================
#cd /etc
#ee group # 加wheel:*:0:root,machm
#su - machm
$mkdir .ssh
$cd .ssh
$ftp aa.bb.cc.dd
ftp>bin
ftp>get Machm.pub
ftp>bye
$ssh-keygen -X -f Machm.pub >> authorized_keys
$su -
#cd /etc/ssh
ee sshd_config
改變內(nèi)容如下:
Protocol 2
HostKey /etc/ssh/ssh_host_dsa_key
PermitRootLogin no
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM no
UseDNS no |
|