001.SSH配置文件

时间:2023-03-09 05:01:13
001.SSH配置文件

一 ssh配置文件路径

1.1 ssh客户端配置文件:

路径:/etc/ssh/ssh_config

1.2 ssh服务端配置文件:

路径:/etc/ssh/sshd_config

二 服务器端常用配置选项

2.1 常见配置项

 Port 22 #端口

 ListenAddress #监听的IP

 Protocol 2 #SSH版本选择

 HostKey /etc/ssh/ssh_host_rsa__key #私钥保存位置

 ServerKeyBits #1024

 ServerFacility AUTH #日志记录ssh登陆情况

 #KeyRegenerationInterval 1h #重新生成服务器密钥的周期

 #ServerKeyBits 1024 #服务器密钥的长度

 LogLevel INFO #记录sshd日志消息的级别

 #PermitRootLogin yes #是否允许root远程ssh登录

 #RSAAuthentication yes #设置是否开启ras密钥登录方式

 #PubkeyAuthentication yes #设置是否开启公钥验登录方式

 #AuthorizedKeysFile .ssh/authorized_keys #设置公钥验证文件的路径

 #PermitEmptyPasswords no #设置是否允许空密码的账号登录

 X11Forwarding yes #设置是否允许X11转发

 GSSAPIAuthentication yes #GSSAPI认证开启

2.3 默认端口修改

注意:ssh默认端口号,建议修改为其他非常用端口。

 #Port 22        					#这行加#号注释掉
Port 2222 #下面添加这一行

2.4 监听IP地址

 ListenAddress

监听的IP,允许某些特定的IP才可以ssh登陆进来。

2.5 采用SSH协议版本

 Protocol 2

默认的ssh版本,建议采用第二代版本。

2.6 私钥配置

 HostKey /etc/ssh/ssh_host_rsa__key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

版本v2的私钥保存路径。

2.7 加密位

 ServerKeyBits 1024

钥匙串的加密位数,默认采用1024位加密。

2.8 日志等级

 ServerFacility AUTH & LogLevel INFO

需要记录日志,并设定日志等级为INFO,建议不用修改。

2.9 GGSSAP认证

 GGSSAPIAuthentication yes

GGSSAP认证默认已开启,经过dns进行认证,尝试将主机IP和域名进行解析。若管理主机无对外域名,建议在管理主机上在客户端的配置文件将此认证关闭。

三 服务器端安全配置选项

 PermitRootLogin yes				#允许root的ssh登陆
PubkeyAuthentication yes #是否使用公钥验证
AuthorizeKeysFile .ssh/authorized_keys #公钥的保存位置
PasswordAuthentication yes #允许使用密码验证登陆
PermitEmptyPasswords no #不允许空密码登陆

注意:如果开启公钥验证,可以关闭允许root登陆、关闭允许使用密码验证登陆,此时将采用公钥验证登陆,无需输入密码。建议采用此更安全的方式,直接使用私钥和公钥匹配的公钥验证方式。

四 SSH其他管理

 [root@imxhy]# yum -y install policycoreutils-python

 [root@imxhy]# semanage port -a -t ssh_port_t -p tcp 2222

 [root@imxhy]# semanage port -l | grep ssh #查看SELinux设置

 [root@imxhy]# firewall-cmd --permanent --add-port=2222/tcp

 [root@imxhy]# systemctl restart firewalld.service

 [root@imxhy]# systemctl restart sshd.service