|
|
[root@sample ~]# vi /etc/ssh/sshd_config ← 用vi打開SSH的配置文件 #Protocol 2,1 ← 找到此行將行頭「#」刪除,再將行末的「,1」刪除,只容許SSH2方式的鏈接 ↓ Protocol 2 ← 修改後變爲此狀態,僅使用SSH2 #ServerKeyBits 768 ← 找到這一行,將行首的「#」去掉,並將768改成1024 ↓ ServerKeyBits 1024 ← 修改後變爲此狀態,將ServerKey強度改成1024比特 #PermitRootLogin yes ← 找到這一行,將行首的「#」去掉,並將yes改成no ↓ PermitRootLogin no ← 修改後變爲此狀態,不容許用root進行登陸 #PasswordAuthentication yes ← 找到這一行,將yes改成no ↓ PasswordAuthentication no ← 修改後變爲此狀態,不容許密碼方式的登陸 #PermitEmptyPasswords no ← 找到此行將行頭的「#」刪除,不容許空密碼登陸 ↓ PermitEmptyPasswords no ← 修改後變爲此狀態,禁止空密碼進行登陸 |
[root@sample ~]# vi /etc/hosts.deny ← 修改屏蔽規則,在文尾添加相應行 # sshd: ALL ← 添加這一行,屏蔽來自全部的SSH鏈接請求 # |
|
[root@sample ~]# /etc/rc.d/init.d/sshd restart ← 從新啓動SSH服務器 Stopping sshd: [ OK ] Starting sshd: [ OK ] ← SSH服務器從新啓動成功 |
|
[root@sample ~]# su - centospub ← 登陸爲通常用戶centospub [centospub@sample ~]$ ssh-keygen -t rsa ← 創建公鑰與私鑰 Generating public/private rsa key pair. Enter file in which to save the key (/home/kaz/.ssh/id_rsa): ← 鑰匙的文件名,這裏保持默認直接回車 Created directory '/home/kaz/.ssh' Enter passphrase (empty for no passphrase): ← 輸入口令 Enter same passphrase again: ← 再次輸入口令 Your identification has been saved in /home/kaz/.ssh/id_rsa. Your public key has been saved in /home/kaz/.ssh/id_rsa.pub. The key fingerprint is: tf:rs:e3:7s:28:59:5s:93:fe:33:84:01:cj:65:3b:8e centospub@sample.centospub.com |
[centospub@sample ~]$ cd ~/.ssh ← 進入用戶SSH配置文件的目錄 [centospub@sample .ssh]$ ls -l ← 列出文件 total 16 -rw------- 1 centospub centospub 951 Sep 4 19:22 id_rsa ← 確認私鑰已被創建 -rw-r--r-- 1 centospub centospub 241 Sep 4 19:22 id_rsa.pub ← 確認公鑰已被創建 [centospub@sample .ssh]$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys ← 公鑰內容輸出到相應文件中 [centospub@sample .ssh]$ rm -f ~/.ssh/id_rsa.pub ← 刪除原來的公鑰文件 [centospub@sample .ssh]$ chmod 400 ~/.ssh/authorized_keys ← 將新創建的公鑰文件屬性設置爲400 |
centospub@sample .ssh]$ exit ← 退出通常用戶的登陸(返回root的登陸) [root@sample ~]# mount /mnt/floppy/ ← 加載軟盤驅動器 [root@sample ~]# mv /home/centospub/.ssh/id_rsa /mnt/floppy/ ← 將剛剛創建的私鑰移動到軟盤 [root@sample ~]# umount /mnt/floppy/ ← 卸載軟盤驅動器 |