關於linux ssh安全的加固方法
為增強安全,先增加一個普通許可權的使用者:
#useradd *****
#passwd ******
//設定密碼
生產機器禁止ROOT遠端SSH登入:
#vim /etc/ssh/sshd_config
把
PermitRootLogin yes
改為
PermitRootLogin no
重啟sshd服務
#service sshd restart
遠端管理用普通使用者*******登入,然後用 su - root 轉換到root使用者拿到最高許可權。
禁止某個使用者登入:
vim /etc/passwd
修改:lynn:x:500:500::/home/lynn:/bin/bash
為: lynn:x:500:500::/home/lynn:/sbin/nologin
修改 : #Port 22
為 : Port *****
使用金鑰認證登入伺服器:
1、以root使用者登入伺服器
2、 vim /etc/ssh/sshd_config
Port 12345
StrictModes no
RSAAuthentication yes
PubkeyAuthentication yes
PermitEmptyPasswords no
PasswordAuthentication no
如果是給非root使用者配置祕鑰認證,下一步需要切換到相應的'使用者做操作:
[root@localhost ]# su - test1
3、ssh-keygen -t rsa -b 1024
a、回車
b、鍵入密碼
4、ls -a /root/ 可以檢視到生成兩個檔案
5、cat id_ > authorized_keys
6、chmod 644 authorized_keys
7、rm -rf id_
8、ls -a /root/ 現在就剩下兩個檔案,authorized_keys是公鑰 id_rsa是金鑰。
9、現在把id_rsa金鑰烤出來。
10、注意先把id_rsa拷貝出來,然後再開一個ssh終端,在啟動服務,以防金鑰沒有成功,ssh也登陸不進去了,也不能修改ssh配置了。
11、再開一個ssh終端,用於不成功的配置用。
12、/etc/init.d/ssh restart
13、如果用samba共享id_rsa檔案,注意檔案的許可權。