轉自:http://blog.csdn.net/zzk197/article/details/7915307
一:簡潔的配置文件
[root@cisco ~]# vi /etc/ssh/sshd_config
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 600
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
RhostsAuthentication no
IgnoreRhosts yes
HostbasedAuthentication no
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
MaxStartups 20
Subsystem sftp /usr/libexec/openssh/sftp-server
~
二、使用公鑰認證
1、原理:首先由用戶生成一對密鑰,然后將公鑰保存在SSH服務器用戶的目錄下.ssh子目錄中的authorized_key文件里(/root/.ssh/authorized_key).私鑰保存在本地計算機.當用戶登陸時,服務器檢查authorized_key文件的公鑰是否與用戶的私鑰對應,如果相符則允許登入,否則拒絕.由於私鑰只有保存在用戶的本地計算機中,因此入侵者就算得到用戶口令,也不能登陸到服務器.
2、啟用公鑰認證
修改配置文件/etc/ssh/sshd_config
將"PasswordAuthentication yes"修改為"PasswordAuthentication no"
3、生成密鑰
[root@rain ~]# 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:
4d:dd:48:af:76:c2:ba:a8:bc:20:f3:28:1d:6a:28:53 root@rain.fish.com
4、將/root/.ssh/id_rsa.pub改名為/root/.ssh/authorized_keys
mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
5、將私鑰id_rsa拷貝到客戶機
A:linux下可以拷貝到/root/.ssh/就可以直接使用了。
三、SSH服務的配置
1、配置SSH服務的運行參數,是通過修改配置文件/etc/ssh/sshd_config實現的。
2、因為SSH服務使用默認的配置已經能夠很好的工作,如果僅僅提供SSH服務不需要修改。這里只介紹一
些常用的選項。
#Port 22
定義了SSH服務監聽的斷口號,SSH服務默認使用的端口號是22
#Proctocol 2,1
定義了SSH服務器使用SSH協議的順序。默認識先使用SSH2協議,如果不成功則使用SSH1協議,為了安全起
見,可以設置只使用SSH2協議。
#ListenAddress 0.0.0.0
定義SSH服務器幫定的IP地址,默認綁定服務器所有可用的IP地址.
#PermitRootLogin yes
定義是否允許管理員登陸
#PermitEmptyPasswords no
定義是否允許空密碼登陸.
#PasswordAuthentication no
定義是否使用口令認證方式,如果准備使用公鑰認證可以設置為no
四 :
吧 id_rsa ,拷到客戶端,在服務器端吧id_rsa.pub 改名為authorized_keys
cat id_rsa.pub >> authorized_keys