SSH remote management and control of TCP Wrappers

A, SSH protocol and configuration files

SSH remote management and control of TCP Wrappers
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
SSH remote management and control of TCP Wrappers

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)
SSH remote management and control of TCP Wrappers

Four, SSH service experimental analysis:

1、默认其他终端可以使用SSH以root身份登录到服务器进行维护。
SSH remote management and control of TCP Wrappers
2、禁止其他终端可以使用SSH以root身份登录到服务器。
(1)执行“vim etc/ssh/sshd_config”命令进入到ssf服务端的配置文件。
SSH remote management and control of TCP Wrappers
(2)删除“PermitRootLogin”开头的“#”符号,并将“yes”改成“no”即可。
SSH remote management and control of TCP Wrappers
(3)执行“systemctl restart sshd”命令重启ssh服务。
SSH remote management and control of TCP Wrappers
(4)终端将无法使用root身份登录。
SSH remote management and control of TCP Wrappers
(5)然而终端可以通过其他用户作为跳板,并使用su命令切换root用户。
SSH remote management and control of TCP Wrappers
(6)我们可以启用PAM认证模块,执行“vim /etc/pam.d/su”命令进入到pam认证模块配置文件。
SSH remote management and control of TCP Wrappers
(7)在配置文件中将第六行开头的“#”符号删除,以开启pam认证。
SSH remote management and control of TCP Wrappers
(8)我们使用id命令开头看到czt用户属于pam认证的wheel组,而lisi用户不属于wheel组。
SSH remote management and control of TCP Wrappers
(9)不隶属于wheel组的lisi用户无法切换root用户,而隶属于wheel组的czt用户方能切换root用户。
SSH remote management and control of TCP Wrappers
3、我们可以设定登录验证的次数来防止密码破解。
(1)执行“vim etc/ssh/sshd_config”命令进入到ssf服务端的配置文件。
SSH remote management and control of TCP Wrappers

(2)删除“MaxAuthTries 6”开头处的“#”符号一开启登录验证功能。
SSH remote management and control of TCP Wrappers

(3)执行“systemctl restart sshd”命令重启ssh服务。
SSH remote management and control of TCP Wrappers

(4)默认情况下我们只输入三次就被指定登出了。

SSH remote management and control of TCP Wrappers
(5)我们可以在登录时即加入一个参数,“ssh -o NumberOfPasswordPrompts=8 [email protected]
”即可按照默认的尝试次数去反复输入密码,输错六次后自动登出。
SSH remote management and control of TCP Wrappers
4、线网上建议设定白名单——AllowUsers
(1)执行“vim etc/ssh/sshd_config”命令进入到ssf服务端的配置文件。
SSH remote management and control of TCP Wrappers

(2)手工在空行处输入“AllowUsers zhaoliu”仅zhaoliu用户可以登录。
SSH remote management and control of TCP Wrappers
(3)执行“systemctl restart sshd”命令重启ssh服务。

SSH remote management and control of TCP Wrappers
(4)其他用户便无法登录到服务器,仅zhaoliu用户可以登录。
SSH remote management and control of TCP Wrappers

五、SSH密钥对登录验证

SSH remote management and control of TCP Wrappers
1、执行“vim etc/ssh/sshd_config”命令进入到ssf服务端的配置文件。
SSH remote management and control of TCP Wrappers

2、将“PubkeyAuthentication yes”前的“#”符号删除以开启密钥对验证功能。
SSH remote management and control of TCP Wrappers
3、在服务端执行“systemctl restart sshd”命令重启ssh服务。
SSH remote management and control of TCP Wrappers

4、在客户端执行“ssh-keygen -t ecdsa
”命令来创建密钥对;按回车键保持默认路径不变;输入密钥对的密码即可获取到加密的密钥。
SSH remote management and control of TCP Wrappers
5、我们在客户端执行“cd .ssh/”命令进入到隐藏文件夹可见“id_ecdsa”私钥文件,以及“id_ecdsa.pub”公钥文件。
SSH remote management and control of TCP Wrappers
6、执行“ ssh-copy-id -i id_ecdsa.pub [email protected]
”命令将公钥文件推送给服务器。
SSH remote management and control of TCP Wrappers
7、在服务端执行“cd .ssh/”命令进入隐藏目录查看是否收到来自ccc用户的公钥文件。
SSH remote management and control of TCP Wrappers
8、客户端下次登录时就需要进行密钥验证,输入密钥密码即可成功登录。
SSH remote management and control of TCP Wrappers
9、然而登录需要进行密码验证交互步骤,我们可以使用代理功能来实现免交互登录(建议不要在公共设备上使用)。
SSH remote management and control of TCP Wrappers
六、sftp服务
1、我们可以执行“sftp [email protected]”命令来登录到服务端的家目录中。
SSH remote management and control of TCP Wrappers

2、在服务端我们可以执行thouch命令创建文件。
SSH remote management and control of TCP Wrappers
3、客户端便可以通过使用“get”命令安全下载到服务端的文件。
SSH remote management and control of TCP Wrappers
4、客户端亦可以使用“put” 命令安全上传文件给服务器。
SSH remote management and control of TCP Wrappers
七、TCP Wrappers 控制
SSH remote management and control of 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.
SSH remote management and control of TCP Wrappers
(3) is written in the whitelist profile "ssh: 192.168.174.110" only allows the host to log the IP addresses.
SSH remote management and control of TCP Wrappers
(4) the implementation of "vim /etc/hosts.deny
" command into the blacklist configuration file.
SSH remote management and control of TCP Wrappers
(5) not to write the configuration file "sshd: ALL" Deny all ip login.
SSH remote management and control of TCP Wrappers
(6) In addition to the terminal IP address "192.168.174.110" can log in, the other can not log on.
SSH remote management and control of TCP Wrappers
(7) implementation of "vim /etc/hosts.allow on the server
" command into the white list profile.
SSH remote management and control of TCP Wrappers
(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.
SSH remote management and control of TCP Wrappers
(9) In addition to the terminal IP address "192.168.174.110" can not log on, other IP host can log on.
SSH remote management and control of TCP Wrappers

Guess you like

Origin blog.51cto.com/14449521/2436884