A, SSH protocol and configuration files
SSH service configuration file:
service names: sshd
main server: / usr / sbin / sshd
server configuration file: / etc / ssh / sshd_config
Second, the service monitor options:
port number, protocol version, monitor IP address
reverse lookup is disabled
Third, the user login control
prohibits the root user, a blank password users
login time, the number of retries
AllowUsers, DenyUsers (manually add the configuration file)
Four, SSH service experimental analysis:
1、默认其他终端可以使用SSH以root身份登录到服务器进行维护。
2、禁止其他终端可以使用SSH以root身份登录到服务器。
(1)执行“vim etc/ssh/sshd_config”命令进入到ssf服务端的配置文件。
(2)删除“PermitRootLogin”开头的“#”符号,并将“yes”改成“no”即可。
(3)执行“systemctl restart sshd”命令重启ssh服务。
(4)终端将无法使用root身份登录。
(5)然而终端可以通过其他用户作为跳板,并使用su命令切换root用户。
(6)我们可以启用PAM认证模块,执行“vim /etc/pam.d/su”命令进入到pam认证模块配置文件。
(7)在配置文件中将第六行开头的“#”符号删除,以开启pam认证。
(8)我们使用id命令开头看到czt用户属于pam认证的wheel组,而lisi用户不属于wheel组。
(9)不隶属于wheel组的lisi用户无法切换root用户,而隶属于wheel组的czt用户方能切换root用户。
3、我们可以设定登录验证的次数来防止密码破解。
(1)执行“vim etc/ssh/sshd_config”命令进入到ssf服务端的配置文件。
(2)删除“MaxAuthTries 6”开头处的“#”符号一开启登录验证功能。
(3)执行“systemctl restart sshd”命令重启ssh服务。
(4)默认情况下我们只输入三次就被指定登出了。
(5)我们可以在登录时即加入一个参数,“ssh -o NumberOfPasswordPrompts=8 [email protected]
”即可按照默认的尝试次数去反复输入密码,输错六次后自动登出。
4、线网上建议设定白名单——AllowUsers
(1)执行“vim etc/ssh/sshd_config”命令进入到ssf服务端的配置文件。
(2)手工在空行处输入“AllowUsers zhaoliu”仅zhaoliu用户可以登录。
(3)执行“systemctl restart sshd”命令重启ssh服务。
(4)其他用户便无法登录到服务器,仅zhaoliu用户可以登录。
五、SSH密钥对登录验证
1、执行“vim etc/ssh/sshd_config”命令进入到ssf服务端的配置文件。
2、将“PubkeyAuthentication yes”前的“#”符号删除以开启密钥对验证功能。
3、在服务端执行“systemctl restart sshd”命令重启ssh服务。
4、在客户端执行“ssh-keygen -t ecdsa
”命令来创建密钥对;按回车键保持默认路径不变;输入密钥对的密码即可获取到加密的密钥。
5、我们在客户端执行“cd .ssh/”命令进入到隐藏文件夹可见“id_ecdsa”私钥文件,以及“id_ecdsa.pub”公钥文件。
6、执行“ ssh-copy-id -i id_ecdsa.pub [email protected]
”命令将公钥文件推送给服务器。
7、在服务端执行“cd .ssh/”命令进入隐藏目录查看是否收到来自ccc用户的公钥文件。
8、客户端下次登录时就需要进行密钥验证,输入密钥密码即可成功登录。
9、然而登录需要进行密码验证交互步骤,我们可以使用代理功能来实现免交互登录(建议不要在公共设备上使用)。
六、sftp服务
1、我们可以执行“sftp [email protected]”命令来登录到服务端的家目录中。
2、在服务端我们可以执行thouch命令创建文件。
3、客户端便可以通过使用“get”命令安全下载到服务端的文件。
4、客户端亦可以使用“put” 命令安全上传文件给服务器。
七、TCP Wrappers 控制
1、访问控制策略的配置文件:
/etc/hosts.allow
/etc/hosts.deny
2、设置访问控制策略:
策略格式:服务列表:客户机地址列表
服务列表:多个服务一逗号分隔,ALL表示所有服务
3、策略的应用顺序:
先检查hosts.allow,找到匹配则允许访问
否则再检查hosts.deny,找到则拒绝访问
若两个文件中均无匹配策略,则默认允许访问
4、实验解析:
(1) implementation of "vim /etc/hosts.allow on the server
" command into the white list profile.
(3) is written in the whitelist profile "ssh: 192.168.174.110" only allows the host to log the IP addresses.
(4) the implementation of "vim /etc/hosts.deny
" command into the blacklist configuration file.
(5) not to write the configuration file "sshd: ALL" Deny all ip login.
(6) In addition to the terminal IP address "192.168.174.110" can log in, the other can not log on.
(7) implementation of "vim /etc/hosts.allow on the server
" command into the white list profile.
(8) in the blacklist only write configuration file "ssh: 192.168.174.110" only refuse to log the IP address of the host, a host of other IP addresses available login.
(9) In addition to the terminal IP address "192.168.174.110" can not log on, other IP host can log on.