[日期:2012-01-29] | 來源:Linux社區 做者:crazyming | [字體:大 中 小] |
SSH簡介:linux
傳統的網絡服務程序,SSH的英文全稱是 Secure Shell,經過使用ssh,能夠對全部的傳輸的數據進行加密,這樣既能夠防止攻擊又能夠防止IP欺騙。安全
SSH 提供2種級別的安全驗證服務器
1,基於口令的安全驗證,這也是咱們經常使用的一種,只要知道用戶名和密碼,就能夠遠程登錄到遠程主機上。網絡
2,基於密鑰的安全認證,就是說用戶必須爲本身建立一對密鑰,並把公用密鑰放到須要訪問的服務器上。ssh
2種安全級別的驗證,後者相對比前者更安全一些,第二種級別不須要在網絡上傳遞口令。ide
SSH密鑰認證登陸配置字體
原理:用戶首先須要爲本身建立一對密鑰:公鑰(用在登陸的服務器上)和私鑰。OPENSSH 公開的密鑰的密碼體質有RSA,DSA等,這裏就用RSA。this
客戶端ip:192.168.72.11加密
服務器ip:192.168.72.129spa
1.密鑰認證的生成
[root@www.linuxidc.com ~]# ifconfig eth0 | awk '/inet addr/{print }'
inet addr:192.168.72.11 Bcast:192.168.72.255 Mask:255.255.255.0
[root@www.linuxidc.com ~]# 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:
04:c5:7a:57:f6:2e:9c:1f:b5:e7:45:b3:11:f3:c7:18 root@www.linuxidc.com
公鑰已經生成
如今把公鑰上傳到另外一臺服務器上去。
[root@www.linuxidc.com ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.72.129
15
The authenticity of host '192.168.72.129 (192.168.72.129)' can't be established.
RSA key fingerprint is 3b:26:19:2e:51:ca:cc:de:ac:bc:00:09:f0:7c:7d:f1.
Are you sure you want to continue connecting (yes/no)? yes #因爲是第一次登陸,服務器要進行確認
Warning: Permanently added '192.168.72.129' (RSA) to the list of known hosts.
Address 192.168.72.129 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.72.129's password:
Now try logging into the machine, with "ssh 'root@192.168.72.129'", and check in:
.ssh/authorized_keys #把公鑰上傳的位置和公鑰的文件名
to make sure we haven't added extra keys that you weren't expecting.
登陸到服務器上,查看公鑰是否上傳
[root@localhost ~]# ll .ssh/authorized_keys
-rw------- 1 root root 391 Aug 4 18:31 .ssh/authorized_keys
說明公鑰上傳成功了。
修改ssh配置文件,設置公鑰認證登陸
將下邊2行的註釋去掉,重啓ssh服務
RSAAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
/etc/init.d/sshd restart
配置完畢,如今開始登陸一下
[root@www.linuxidc.com ~]# ssh 192.168.72.129
Address 192.168.72.129 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Last login: Thu Aug 4 18:08:05 2011 from 192.168.72.1
[root@localhost ~]#
如今不用輸入密碼,就能夠登陸了。退出登陸
[root@localhost ~]# exit
logout
Connection to 192.168.72.129 closed.
linux ssh 密鑰認證無需輸入密碼便可登陸,在設置密鑰的同時,也能夠輸入密碼,便可密碼+密鑰認證就能夠完成!