To take the RHCE test, you must record the details and important content for the RHCE test. Hope you can pass the RHCE test smoothly! Tang sir said he wanted a full score. I hope I can afford it! 1: Clear the default firewall, the default firewall is quite strict, so this step is very important [root @ server ~] # ServiceiptablesstopFlushingfirewallrules: [OK] Settingchainstopolic
To take the RHCE test, you must record the details and important content for the RHCE test. Hope you can pass the RHCE test smoothly! Tang sir said he wanted a full score. I hope I can afford it!
1: Clear the default firewall. The default firewall is quite strict, so this step is very important.
[Root @ server ~] # Service iptables stop
Flushing firewall rules: [OK]
Setting chains to policy ACCEPT: filter [OK]
Unloading iptables modules: [OK]
[Root @ server ~] # Service iptables save // save the cleared rules. Otherwise, the default rules will take effect again after the firewall is restarted.
[Root @ server ~] # Iptables-l input-n-v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
Pkts bytes target prot opt in out source destination
2: Determine that The selinux status is enforcing.
[Root @ server ~] # Getenforce // determine that selinux is in force state. If not, modify the/etc/sysconfig/selinux file.
Enforcing
[Root @ server ~] # Getsebool-a | grep samba // samba shares the home directory. You need to adjust the Boolean value of samba_enable_home_dirs.
Samba_domain_controller --> off
Samba_enable_home_dirs --> off
Samba_export_all_ro --> off
Samba_export_all_rw --> off
Samba_cmd_nfs --> off
Use_samba_home_dirs --> off
Export _use_samba --> off
[Root @ server ~] # Setsebool-P samba_enable_home_dirs on //-P indicates that it takes effect permanently. Otherwise, it will become invalid after restart.
[Root @ server ~] # Getsebool-a | grep samba
Samba_domain_controller --> off
Samba_enable_home_dirs --> on
[Root @ server ~] # Ls-Zd/share // selinux of samba's shared directory needs to be set to samba_share_t
Drwxr-xr-x root: object_r: user_home_t/share/
[Root @ server ~] # Chcon-R-t samba_assist_t/share //-R indicates Recursion
[Root @ server ~] # Ls-Zd/share/
Drwxr-xr-x root: object_r: samba_assist_t/share/
[Root @ server ~] # Echo "test">/share/test.txt
[Root @ server ~] # Ls-Z/share/
-Rw-r -- root: object_r: samba_cmd_t test.txt
3: ssh host-and user-level access control
[Root @ server ~] # Tail-2/etc/passwd
Zhang: x: 500: 500:/home/zhang:/bin/bash
Huang: x: 501: 501:/home/huang:/bin/bash
[Root @ server ~] # Grep-I 'allowusers'/etc/ssh/sshd_config // Add the allowusers configuration to the ssh main configuration file. Separate users with space characters and enter the root and user to be allowed.
AllowUsers root huang // only root and huang users can perform ssh login.
[Root @ server ~] # Ssh zhang@127.0.0.1
The authenticity of host' 127. 0.0.1 (127.0.0.1) 'can't be established.
RSA key fingerprint is 3a: 5d: 33: 3c: c5: 04: 8f: 31: 19: 38: 1b: 9a: b4: 75: 4c: 51.
Are you sure you want to continue connecting (yes/no )? Yes
Warning: Permanently added '2017. 0.0.1 '(RSA) to the list of known hosts.
Zhang@127.0.0.1's password:
Permission denied, please try again. // login denied
[Root @ server ~] # Ssh huang@127.0.0.1
Huang@127.0.0.1's password:
Last login: Wed Mar 24 21:43:01 2010 from 192.168.100.254
[Huang @ server ~] $
[Root @ server ~] # Ldd/usr/sbin/sshd | grep wrap // The ldd command is used to check whether the binary file of the program is compiled and connected to libwrap. You can also view the stings command.
Libwrap. so.0 =>/lib/libwrap. so.0 (0x00394000)
The tcp_wraper mechanism is to read/etc/hosts first. allow file to see if it is explicitly allowed. If it is allowed, it will be passed directly. If it is not explicitly allowed, read/etc/hosts again. whether the deny file is explicitly rejected. If it is explicitly rejected, it is rejected. If it is not explicitly rejected, it is allowed. Therefore, we usually choose to write the/etc/hosts. deny file to reject
[Root @ server ~] # Tail-1/etc/hosts. deny // the IP address 192.168.100.254 is not allowed for ssh login.
Sshd: 192.168.100.254
[Root @ client ~] # Ifconfig eth1 | grep 'inet addr '| cut-d':'-f 2 | cut-d'-f 1
192.168.100.254
[Root @ client ~] # Ping-c 1 192.168.100.20
PING 192.168.100.20 (192.168.100.20) 56 (84) bytes of data.
64 bytes from 192.168.100.20: icmp_seq = 1 ttl = 64 time = 33.0 MS
[Root @ client ~] # Ssh 192.168.100.20
Ssh_exchange_identification: Connection closed by remote host // it has been rejected by tcp_wraper
[Root @ server ~] # Iptables-a input-s 192.168.100.254-p tcp -- dport 22-j REJECT // You can also REJECT it on the INPUT chain of iptables
[Root @ server ~] # Service iptables save
Saving firewall rules to/etc/sysconfig/iptables: [OK]
[Root @ client ~] # Ssh 192.168.100.20
Ssh: connect to host 192.168.100.20 port 22: Connection refused