001.SSH配置文件

一 ssh配置文件路径

1.1 ssh客户端配置文件:

路径:/etc/ssh/ssh_config

1.2 ssh服务端配置文件:

路径:/etc/ssh/sshd_config

二 服务器端常用配置选项

2.1 常见配置项

  1 Port 22 #端口
  2 
  3 ListenAddress #监听的IP
  4 
  5 Protocol 2 #SSH版本选择
  6 
  7 HostKey /etc/ssh/ssh_host_rsa__key #私钥保存位置
  8 
  9 ServerKeyBits #1024
 10 
 11 ServerFacility AUTH #日志记录ssh登陆情况
 12 
 13 #KeyRegenerationInterval 1h #重新生成服务器密钥的周期
 14 
 15 #ServerKeyBits 1024 #服务器密钥的长度
 16 
 17 LogLevel INFO #记录sshd日志消息的级别
 18 
 19 #PermitRootLogin yes #是否允许root远程ssh登录
 20 
 21 #RSAAuthentication yes #设置是否开启ras密钥登录方式
 22 
 23 #PubkeyAuthentication yes #设置是否开启公钥验登录方式
 24 
 25 #AuthorizedKeysFile .ssh/authorized_keys #设置公钥验证文件的路径
 26 
 27 #PermitEmptyPasswords no #设置是否允许空密码的账号登录
 28 
 29 X11Forwarding yes #设置是否允许X11转发
 30 
 31 GSSAPIAuthentication yes #GSSAPI认证开启

2.3 默认端口修改

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

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

2.4 监听IP地址

  1 ListenAddress

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

2.5 采用SSH协议版本

  1 Protocol 2

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

2.6 私钥配置

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

版本v2的私钥保存路径。

2.7 加密位

  1 ServerKeyBits 1024

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

2.8 日志等级

  1 ServerFacility AUTH & LogLevel INFO

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

2.9 GGSSAP认证

  1 GGSSAPIAuthentication yes

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

三 服务器端安全配置选项

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

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

四 SSH其他管理

  1 [root@imxhy]# yum -y install policycoreutils-python
  2 
  3 [root@imxhy]# semanage port -a -t ssh_port_t -p tcp 2222
  4 
  5 [root@imxhy]# semanage port -l | grep ssh #查看SELinux设置
  6 
  7 [root@imxhy]# firewall-cmd --permanent --add-port=2222/tcp
  8 
  9 [root@imxhy]# systemctl restart firewalld.service
 10 
 11 [root@imxhy]# systemctl restart sshd.service
原文地址:https://www.cnblogs.com/itzgr/p/9888726.html