linux使用證書ssh登陸

ssh-keygen -t rsa
指定密鑰路徑和輸入口令之後,即在/home/msa/.ssh/中生成公鑰和私鑰:id_rsa id_rsa.pub(root賬號下在/root/.ssh/中)
輸入口令之後在CRT中登陸的時候需驗證口令

如以下例子
[root@kangta-01 .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
06:25:cd:e3:b6:e7:13:76:3e:59:81:4f:77:43:bd:0a root@kangta-01
[root@kangta-01 .ssh]# ll
總計 12
-rw------- 1 root root 1743 11-28 23:47 id_rsa
-rw-r--r-- 1 root root  396 11-28 23:47 id_rsa.pub
-rw-r--r-- 1 root root  395 11-17 00:38 known_hosts


cat id_rsa.pub >> authorized_keys
至於爲什麼要生成這個文件,因爲sshd_config裏面寫的就是這個。
然後chmod 400 authorized_keys,稍微保護一下。

在CRT上的終端可用sz id_rsa拉回本地,然後把服務器上的id_rsa和id_rsa.pub幹掉

6)配置/etc/ssh/sshd_config
Protocol 2
ServerKeyBits 1024
PermitRootLogin no  #禁止root登錄而已,與本文無關,加上安全些

#以下三行沒什麼要改的,把默認的#註釋去掉就行了
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile    .ssh/authorized_keys

PasswordAuthentication no
PermitEmptyPasswords no

7)重啓sshd
/sbin/service sshd restart

8)轉換證書格式
運行CRT,在tools下convert private key to openssh format 轉換id_rsa爲crt的ppk證書文件

9)配置CRT登錄
在connection--SSH--publickey中,點擊Browse,選擇剛剛轉換好的證書。
然後在connection-Data填寫一下auto login username,例如我的是root
在session中填寫服務器的IP地址,高興的話可以save一下

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章