CentOS 7安装完成后基本配置

简介: 版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/76984944 1、添加...
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/76984944

1、添加用户

新增名为"wang"的用户

[root@vdevops ~]# useradd wang #添加账户
[root@vdevops ~]# passwd wang #设置密码
Changing password for user wang.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@vdevops ~]# exit #退出

以用户"wang"为例,设置其为唯一拥有管理员权限的账户

[root@vdevops ~]# usermod -G wheel wang
[root@vdevops ~]# vim /etc/pam.d/su

[html]  view plain  copy
 print ?
  1. #%PAM-1.0  
  2. auth            sufficient      pam_rootok.so  
  3. # Uncomment the following line to implicitly trust users in the "wheel" group.  
  4. #auth           sufficient      pam_wheel.so trust use_uid  
  5. # Uncomment the following line to require a user to be in the "wheel" group.  
  6. # 取消下面一行的注释  
  7. auth            required        pam_wheel.so use_uid  
  8. auth            substack        system-auth  
  9. auth            include         postlogin  
  10. account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet  
  11. account         include         system-auth  
  12. password        include         system-auth  
  13. session         include         system-auth  
  14. session         include         postlogin  
  15. session         optional        pam_xauth.so  
设置root账户的邮件转发

# Person who should get root's mail
# 最后一行,取消注释,改变用户名称
root: wang

2、设置防火墙和SELINUX

【1】防火墙

查看防火墙状态

[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# systemctl status firewalld  
  2. ● firewalld.service - firewalld - dynamic firewall daemon  
  3.    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)  
  4.    Active: active (running) since Wed 2016-10-26 01:09:49 CST; 1h 36min ago  
  5.  Main PID: 744 (firewalld)  
  6.    CGroup: /system.slice/firewalld.service  
  7.            └─744 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid  
  8.   
  9. Oct 26 01:09:46 vdevops.com systemd[1]: Starting firewalld - dynamic firewall daemon...  
  10. Oct 26 01:09:49 vdevops.com systemd[1]: Started firewalld - dynamic firewall daemon.  
防火墙基本操作

[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# systemctl start firewalld   #启动防火墙  
  2. [root@vdevops ~]# systemctl enable firewalld  #设置防火墙开机自启  

默认情况下,“public”区域应用于NIC,dhcpv6-client和ssh是允许的。当使用“firewall-cmd”命令操作时,如果输入命令不带“--zone = ***”规范,则配置设置为默认区域。

[html]  view plain  copy
 print ?
  1. #显示默认区域  
  2. [root@vdevops ~]# firewall-cmd --get-default-zone   
  3. public  
  4. #显示当前设置  
  5. [root@vdevops ~]# firewall-cmd --list-all  
  6. public (default, active)  
  7.   interfaces: eno16777736  
  8.   sources:   
  9.   services: dhcpv6-client ssh  
  10.   ports:   
  11.   masquerade: no  
  12.   forward-ports:   
  13.   icmp-blocks:   
  14.   rich rules:   
  15. #显示全部区域  
  16. [root@vdevops ~]# firewall-cmd --list-all-zones  
  17. block  
  18.   interfaces:   
  19.   sources:   
  20.   services:   
  21.   ports:   
  22.   masquerade: no  
  23.   forward-ports:   
  24.   icmp-blocks:   
  25.   rich rules:   
  26.       
  27. dmz  
  28.   interfaces:   
  29.   sources:   
  30.   services: ssh  
  31.   ports:   
  32.   masquerade: no  
  33.   forward-ports:   
  34.   icmp-blocks:   
  35.   rich rules:   
  36. ...  
  37. #显示特定区域允许的服务  
  38. [root@vdevops ~]# firewall-cmd --list-service --zone=external  
  39. ssh  
  40. #改变默认区域  
  41. [root@vdevops ~]# firewall-cmd --set-default-zone=external  
  42. success  
  43. #改变制定区域的接口  
  44. [root@vdevops ~]# firewall-cmd --change-interface=eth1 --zone=external  
  45. success  
  46. #显示制定区域的状态  
  47. [root@vdevops ~]# firewall-cmd --list-all --zone=external  
  48. external (default, active)  
  49.   interfaces: eno16777736 eth1  
  50.   sources:   
  51.   services: ssh  
  52.   ports:   
  53.   masquerade: yes  
  54.   forward-ports:   
  55.   icmp-blocks:   
  56.   rich rules:   
  57. #注:改变制定区域的接口,前提是次接口在当前系统是存在的  
显示默认定义的服务
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# firewall-cmd --get-services  
  2. RH-Satellite-6 amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns freeipa-ldap freeipa-ldaps freeipa-replication ftp high-availability http https imaps ipp ipp-client ipsec iscsi-target kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind rsyncd samba samba-client smtp ssh telnet tftp tftp-client transmission-client vdsm vnc-server wbem-https  
  3. #定义文件路径如下,如果需要添加新的定义文件,在下面目录添加相应的XML文件  
  4. [root@vdevops ~]# ls /usr/lib/firewalld/services   
  5. amanda-client.xml  freeipa-ldap.xml         ipp.xml           libvirt.xml  pmcd.xml        RH-Satellite-6.xml  tftp-client.xml  
  6. bacula-client.xml  freeipa-replication.xml  ipsec.xml         mdns.xml     pmproxy.xml     rpc-bind.xml        tftp.xml  
  7. bacula.xml         ftp.xml                  iscsi-target.xml  mountd.xml   pmwebapis.xml   rsyncd.xml          transmission-client.xml  
  8. dhcpv6-client.xml  high-availability.xml    kerberos.xml      ms-wbt.xml   pmwebapi.xml    samba-client.xml    vdsm.xml  
  9. dhcpv6.xml         https.xml                kpasswd.xml       mysql.xml    pop3s.xml       samba.xml           vnc-server.xml  
  10. dhcp.xml           http.xml                 ldaps.xml         nfs.xml      postgresql.xml  smtp.xml            wbem-https.xml  
  11. dns.xml            imaps.xml                ldap.xml          ntp.xml      proxy-dhcp.xml  ssh.xml  
  12. freeipa-ldaps.xml  ipp-client.xml           libvirt-tls.xml   openvpn.xml  radius.xml      telnet.xml  
添加或删除允许的服务,重新启动系统后,更改将恢复。如果永久更改设置,请添加“--permanent”选项。
[html]  view plain  copy
 print ?
  1. #以添加http服务为例  
  2. [root@vdevops ~]# firewall-cmd --add-service=http  
  3. success  
  4. [root@vdevops ~]# firewall-cmd --list-service  
  5. http ssh  
  6. #移除添加的http  
  7. <pre name="code" class="html">[root@vdevops ~]# firewall-cmd --remove-service=http  
  8. success  
  9. [root@vdevops ~]# firewall-cmd --list-service  
  10. ssh  
  11. #添加http服务,永久生效   
[root@vdevops ~]# firewall-cmd --add-service=http --permanentsuccess
[root@vdevops ~]# firewall-cmd --reloadsuccess[root@vdevops ~]# firewall-cmd --list-servicehttp ssh 
 添加和移除端口
  
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# firewall-cmd --add-port=465/tcp                #添加端口  
  2. success  
  3. [root@vdevops ~]# firewall-cmd --list-port  
  4. 465/tcp  
  5. [root@vdevops ~]# firewall-cmd --remove-port=465/tcp             #移除端口  
  6. success  
  7. [root@vdevops ~]# firewall-cmd --list-port  
  8. [root@vdevops ~]# firewall-cmd --add-port=465/tcp --permanent    #添加端口,永久生效  
  9. success  
  10. [root@vdevops ~]# firewall-cmd --reload  
  11. success  
  12. [root@vdevops ~]# firewall-cmd --list-port  
  13. 465/tcp  
加或删除禁止的ICMP类型
[html]  view plain  copy
 print ?
  1. [root@dlp ~]# firewall-cmd --add-icmp-block=echo-request      #添加禁止回应请求  
  2. success  
  3. [root@dlp ~]# firewall-cmd --list-icmp-blocks  
  4. echo-request  
  5. [root@dlp ~]# firewall-cmd --remove-icmp-block=echo-request   #移除添加的参数  
  6. success  
  7. [root@dlp ~]# firewall-cmd --list-icmp-blocks  
  8. [root@dlp ~]# firewall-cmd --get-icmptypes                    #显示ICMP支持的功能  
  9. destination-unreachable echo-reply echo-request parameter-problem redirect  
  10. router-advertisement router-solicitation source-quench time-exceeded   
【2】如果不需要防火墙服务,关闭如下
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# systemctl stop firewalld                      #停止防火墙服务  
  2. [root@vdevops ~]# systemctl disable firewalld                   #禁止防火墙开机自启  
  3. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.  
  4. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.  
3、SELinux
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# getenforce                 #查看SELINUX工作模式  
  2. Enforcing  
  3. [root@vdevops ~]# sed -i 's/SELINUX=Enforcing/SELINUX=disabled/' /etc/selinux/config    #禁用SELINUX  
  4. [root@vdevops ~]# setenforce 0                #临时禁用SELINUX,无需重启  
4、网络设置
【1】、设置静态IP和改变接口名称
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# nmcli c modify eno16777736 ipv4.addresses 10.1.1.56/24           #设置静态IP  
  2. [root@vdevops ~]# nmcli c modify eno16777736 ipv4.gateway 10.1.1.1                 #设置网关  
  3. [root@vdevops ~]# nmcli c modify eno16777736 ipv4.dns 10.1.1.1                     #设置DNS  
  4. [root@vdevops ~]# nmcli c modify eno16777736 ipv4.method manual                    #设置ipv4的类型为静态  
  5. [root@vdevops ~]# nmcli c down eno16777736;nmcli c up eno16777736                  #重启网络接口  
  6. Connection 'eno16777736' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/0)  
  7. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)  
  8. [root@vdevops ~]# nmcli d show eno16777736                                         #查看网络接口状态  
  9. GENERAL.DEVICE:                         eno16777736  
  10. GENERAL.TYPE:                           ethernet  
  11. GENERAL.HWADDR:                         00:0C:29:B6:F5:5E  
  12. GENERAL.MTU:                            1500  
  13. GENERAL.STATE:                          100 (connected)  
  14. GENERAL.CONNECTION:                     eno16777736  
  15. GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/1  
  16. WIRED-PROPERTIES.CARRIER:               on  
  17. IP4.ADDRESS[1]:                         10.1.1.56/24  
  18. IP4.GATEWAY:                            10.1.1.1  
  19. IP4.DNS[1]:                             10.1.1.1  
  20. IP6.ADDRESS[1]:                         fe80::20c:29ff:feb6:f55e/64  
  21. IP6.GATEWAY:                              
  22. [root@vdevops ~]# ip addr show                                                     #查看IP状态  
  23. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN   
  24.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
  25.     inet 127.0.0.1/8 scope host lo  
  26.        valid_lft forever preferred_lft forever  
  27.     inet6 ::1/128 scope host   
  28.        valid_lft forever preferred_lft forever  
  29. 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000  
  30.     link/ether 00:0c:29:b6:f5:5e brd ff:ff:ff:ff:ff:ff  
  31.     inet 10.1.1.56/24 brd 10.1.1.255 scope global eno16777736  
  32.        valid_lft forever preferred_lft forever  
  33.     inet6 fe80::20c:29ff:feb6:f55e/64 scope link   
  34.        valid_lft forever preferred_lft forever  
【2】禁用IPV6
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# vim /etc/default/grub   
  2. #第六行,添加  
  3. GRUB_CMDLINE_LINUX="crashkernel=auto <span style="color:#FF0000;">ipv6.disable=1</span> rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"  
  4. [root@vdevops ~]# grub2-mkconfig -o /boot/grub2/grub.cfg  
  5. Generating grub configuration file ...  
  6. Found linux image: /boot/vmlinuz-3.10.0-327.36.2.el7.x86_64  
  7. Found initrd image: /boot/initramfs-3.10.0-327.36.2.el7.x86_64.img  
  8. Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64  
  9. Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img  
  10. Found linux image: /boot/vmlinuz-0-rescue-d1b9467b8b744a3db391f2c15fe58a94  
  11. Found initrd image: /boot/initramfs-0-rescue-d1b9467b8b744a3db391f2c15fe58a94.img  
  12. done  
  13. [root@vdevops ~]# reboot   #重启系统  
【3】如果要将网络接口名称用作ethX,请按如下所示进行配置。
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# vim /etc/default/grub   
  2. #第六行添加  
  3. GRUB_CMDLINE_LINUX="crashkernel=auto ipv6.disable=1 <span style="color:#FF0000;">net.ifnames=0</span> rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet  
  4. [root@vdevops ~]# grub2-mkconfig -o /boot/grub2/grub.cfg  
  5. Generating grub configuration file ...  
  6. Found linux image: /boot/vmlinuz-3.10.0-327.36.2.el7.x86_64  
  7. Found initrd image: /boot/initramfs-3.10.0-327.36.2.el7.x86_64.img  
  8. Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64  
  9. Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img  
  10. Found linux image: /boot/vmlinuz-0-rescue-d1b9467b8b744a3db391f2c15fe58a94  
  11. Found initrd image: /boot/initramfs-0-rescue-d1b9467b8b744a3db391f2c15fe58a94.img  
  12. done  
4、服务设置
[1]、查看服务状态
[html]  view plain  copy
 print ?
  1. # 显示正在运行的服务  
  2. [root@vdevops ~]# systemctl -t service  
  3. UNIT                                    LOAD   ACTIVE SUB     DESCRIPTION  
  4. auditd.service                          loaded active running Security Auditing Service  
  5. avahi-daemon.service                    loaded active running Avahi mDNS/DNS-SD Stack  
  6. crond.service                           loaded active running Command Scheduler  
  7. dbus.service                            loaded active running D-Bus System Message Bus  
  8. getty@tty1.service                      loaded active running Getty on tty1  
  9. ...  
  10. ...  
  11. ...  
  12. systemd-udevd.service                   loaded active running udev Kernel Device Manager  
  13. systemd-update-utmp.service             loaded active exited  Update UTMP about System Reboot/Shutdown  
  14. systemd-user-sessions.service           loaded active exited  Permit User Sessions  
  15. systemd-vconsole-setup.service          loaded active exited  Setup Virtual Console  
  16. tuned.service                           loaded active running Dynamic System Tuning Daemon  
  17.   
  18. LOAD   = Reflects whether the unit definition was properly loaded.  
  19. ACTIVE = The high-level unit activation state, i.e. generalization of SUB.  
  20. SUB    = The low-level unit activation state, values depend on unit type.  
  21.   
  22. 39 loaded units listed. Pass --all to see loaded but inactive units, too.  
  23. To show all installed unit files use 'systemctl list-unit-files'.  
  24.   
  25. # 显示所有服务  
  26. [root@vdevops ~]# systemctl list-unit-files -t service  
  27.   
  28. UNIT FILE                               STATE  
  29. auditd.service                          enabled  
  30. autovt@.service                         disabled  
  31. avahi-daemon.service                    enabled  
  32. blk-availability.service                disabled  
  33. brandbot.service                        static  
  34. ...  
  35. ...  
  36. ...  
  37. systemd-user-sessions.service           static  
  38. systemd-vconsole-setup.service          static  
  39. teamd@.service                          static  
  40. tuned.service                           enabled  
  41. wpa_supplicant.service                  disabled  
  42.   
  43. 125 unit files listed.  
[2]、设置停止启动自动的服务
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# systemctl stop postfix                      #停止服务  
  2. [root@vdevops ~]# systemctl disable postfix                      
  3. Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.  
  4. [root@vdevops ~]# systemctl start postfix  
  5. [root@vdevops ~]# systemctl enable postfix  
  6. Created symlink from /etc/systemd/system/multi-user.target.wants/postfix.service to /usr/lib/systemd/system/postfix.service.  
  7. [root@vdevops ~]# systemctl status postfix  
  8. ● postfix.service - Postfix Mail Transport Agent  
  9.    Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)  
  10.    Active: active (running) since Wed 2016-10-26 18:40:35 CST; 15s ago  
  11.  Main PID: 10071 (master)  
  12.    CGroup: /system.slice/postfix.service  
  13.            ├─10071 /usr/libexec/postfix/master -w  
  14.            ├─10072 pickup -l -t unix -u  
  15.            └─10073 qmgr -l -t unix -u  
  16.   
  17. Oct 26 18:40:35 vdevops.com postfix[9999]: /usr/sbin/postconf: warning: inet_protocols: disabling IPv6 name/address support: Address ...rotocol  
  18. Oct 26 18:40:35 vdevops.com postfix[9999]: /usr/sbin/postconf: warning: inet_protocols: disabling IPv6 name/address support: Address ...rotocol  
  19. Oct 26 18:40:35 vdevops.com postfix[9999]: postsuper: warning: inet_protocols: disabling IPv6 name/address support: Address family no...rotocol  
  20. Oct 26 18:40:35 vdevops.com postfix[9999]: /usr/sbin/postconf: warning: inet_protocols: disabling IPv6 name/address support: Address ...rotocol  
  21. Oct 26 18:40:35 vdevops.com postfix/master[10071]: warning: inet_protocols: disabling IPv6 name/address support: Address family not s...rotocol  
  22. Oct 26 18:40:35 vdevops.com postfix/master[10071]: warning: inet_protocols: disabling IPv6 name/address support: Address family not s...rotocol  
  23. Oct 26 18:40:35 vdevops.com postfix/master[10071]: daemon started -- version 2.10.1, configuration /etc/postfix  
  24. Oct 26 18:40:35 vdevops.com systemd[1]: Started Postfix Mail Transport Agent.  
  25. Oct 26 18:40:35 vdevops.com postfix/qmgr[10073]: warning: inet_protocols: disabling IPv6 name/address support: Address family not sup...rotocol  
  26. Oct 26 18:40:35 vdevops.com postfix/pickup[10072]: warning: inet_protocols: disabling IPv6 name/address support: Address family not s...rotocol  
  27. Hint: Some lines were ellipsized, use -l to show in full.  
[3]、还有一些SysV服务。它们由chkconfig控制,如下所示
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# chkconfig --list  
  2.   
  3. Note: This output shows SysV services only and does not include native  
  4.       systemd services. SysV configuration data might be overridden by native  
  5.       systemd configuration.  
  6.   
  7.       If you want to list systemd services use 'systemctl list-unit-files'.  
  8.       To see services enabled on particular target use  
  9.       'systemctl list-dependencies [target]'.  
  10.   
  11. netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off  
  12. network         0:off   1:off   2:on    3:on    4:on    5:on    6:off  
5、更新系统添加其他源
yum update -y

添加其它源
添加一些有用的外部存储库来安装有用的软件
【1】安装插件以向每个安装的存储库添加优先级。
[html]  view plain  copy
 print ?
  1.  [root@vdevops ~]# yum -y install yum-plugin-priorities  
  2. # 设置官方源的优先级为[priority=1]  
  3. [root@vdevops ~]# sed -i -e "s/\]$/\]\npriority=1/g" /etc/yum.repos.d/CentOS-Base.repo   
【2】添加从Fedora项目提供的EPEL存储库
[html]  view plain  copy
 print ?
  1.  [root@vdevops ~]# yum -y install epel-release  
  2. # 设置优先级[priority=5]  
  3. [root@vdevops ~]# sed -i -e "s/\]$/\]\npriority=5/g" /etc/yum.repos.d/epel.repo  
  4.   
  5. # 可以通过设置enabled=0,来控制安装软件包时使用相应的源  
  6. [root@vdevops ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo  
  7.   
  8. # 如果[enabled=0], 使用下面命令安装软件包  
  9. [root@vdevops ~]# yum --enablerepo=epel install [Package]  
【3】添加CentOS SCLo软件集合存储库。
[html]  view plain  copy
 print ?
  1.  [root@vdevops ~]# yum -y install centos-release-scl-rh centos-release-scl  
  2. # 设置优先级[priority=10]  
  3. [root@vdevops ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo  
  4. [root@vdevops ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo  
  5.   
  6. # 设置 [enabled=0]  
  7. [root@vdevops ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo  
  8. [root@vdevops ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo  
  9.   
  10. # 设置[enabled=0], 通过下面命令使用相应源  
  11. [root@vdevops ~]# yum --enablerepo=centos-sclo-rh install [Package]  
  12. [root@vdevops ~]# yum --enablerepo=centos-sclo-sclo install [Package]  
【4】添加Remi的RPM存储库,它提供了许多有用的包
[html]  view plain  copy
 print ?
  1.  [root@vdevops ~]# yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm  
  2. # 设置优先级 [priority=10]  
  3. [root@vdevops ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/remi-safe.repo   
6、配置特色的vim
【1】安装vim
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# yum -y install vim-enhanced  
【2】设置别名
设置命令别名。 (适用于以下所有用户,如果您申请某个用户,请在“〜/ .bashrc”中写入相同的设置)
[html]  view plain  copy
 print ?
  1.  [root@dlp ~]# vi /etc/profile  
  2. # 在最后添加下面一行内容  
  3. alias vi='vim'  
  4. [root@dlp ~]# source /etc/profile  #重载  
  5. 或者  
  6. echo "alias vi='vim'>> /etc/profile && source /etc/profile  
【3】配置vim,针对所有用户生效修改/etc/vimrc,针对特定用户生效修改~/.vimrc
主要用语法高亮,插件使用,自动缩进等功能,本文不做详细操作,后续会专门写一篇关于优化vim使用的博文,工欲善其事必先利其器
7、设置sudo
配置sudo以区分用户的职责,如果一些人共享权限,必手动安装sudo,因为它默认安装,即使“最小安装”
【1】设置普通用户拥有root的所有权限
[html]  view plain  copy
 print ?
  1.  [root@vdevops ~]# visudo  
  2. #  添加下面一行,使用户“wang”拥有root的所有权限  
  3. wang    ALL=(ALL)       ALL  
  4.   
  5. # 普通用户使用root命令  
  6. # 确保用户为 'wang'  
  7.   
  8. [wang@vdevops ~]$ /usr/bin/cat /etc/shadow  
  9. cat: /etc/shadow: Permission denied# denied normally  
  10. [wang@vdevops ~]$ sudo /usr/bin/cat /etc/shadow  
  11.   
  12. [sudo] password for cent:# own password  
  13.   
  14. daemon:*:16231:0:99999:7:::  
  15. adm:*:16231:0:99999:7:::  
  16. lp:*:16231:0:99999:7:::  
  17. ...  
  18. ...  
  19. # 输入wang的密码可以看到执行结果  
[html]  view plain  copy
 print ?
  1. 【2】设置用户不能执行危险命令  
[html]  view plain  copy
 print ?
  1.  [root@vdevops ~]# visudo  
  2. # 49行: 定义别名SHUTDOWN  
  3.   
  4. Cmnd_Alias SHUTDOWN = /sbin/halt, /sbin/shutdown, /sbin/poweroff, /sbin/reboot, /sbin/init  
  5. # 设置用户wang不能执行别名SHUTDOWN对应的命令  
  6. wang ALL=(ALL) ALL, !SHUTDOWN  
  7. # 确保用户为'wang'  
  8. [wang@vdevops ~]$ sudo /sbin/shutdown -r now  
  9.   
  10. Sorry, user cent is not allowed to execute '/sbin/shutdown -r now' as root on vdevops.com.   # denied normally  
【3】创建一个特殊的组,组用户可以执行部分root命令
[html]  view plain  copy
 print ?
  1.  [root@vdevops ~]# visudo  
  2. # 51行: 为管理用户的几个命令设置别名为USERMGR  
  3.   
  4. Cmnd_Alias USERMGR = /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod, /usr/bin/passwd  
  5.   
  6. # 最后一行添加  
  7. %usermgr ALL=(ALL) USERMGR  
  8. [root@vdevops ~]# groupadd usermgr  
  9.   
  10. [root@vdevops ~]# usermod -G usermgr wang  
  11.   
  12. # 确保用户为wang  
  13. [wang@vdevops ~]$ sudo /usr/sbin/useradd testuser  
  14. #输入用户wang的密码,查看创建结果,显示成功  
  15. [wang@vdevops ~]$ sudo /usr/bin/passwd testuser  
  16. Changing password for user testuser.  
  17. New UNIX password:  
  18. Retype new UNIX password:  
  19. passwd: all authentication tokens updated successfully.   
【4】设置sudo日志
sudo的日志保存在/ var / log / secure中,但它中有很多种类的日志。如果你想保持只有sudo的日志在一个文件,设置如下:
[html]  view plain  copy
 print ?
  1. [root@vdevops ~]# visudo  
  2. # 最后一行添加  
  3. Defaults syslog=local1  
  4. [root@vdevops ~]# vi /etc/rsyslog.conf  
  5. # 在54行修改,添加<span style="color:#FF6666;">local1.none</span>  
  6. *.info;mail.none;authpriv.none;cron.none;<span style="color:#FF6666;">local1.none</span>  
  7.   /var/log/messages  
  8. # 添加下面一行内容  
  9. local1.*                                                /var/log/sudo.log  
  10.   
  11. [root@vdevops ~]# systemctl restart rsyslog    #重启rsyslog服务  
目录
相关文章
|
1月前
|
Linux 网络安全 数据安全/隐私保护
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
142 0
|
2月前
|
关系型数据库 MySQL Linux
centos7.0环境下安装MySql_8.0.12
centos7.0环境下安装MySql_8.0.12
|
1月前
|
存储 JavaScript Linux
Linux环境下安装nmp(Centos环境)保姆级教学 一步到位
Linux环境下安装nmp(Centos环境)保姆级教学 一步到位
|
2月前
|
关系型数据库 MySQL Linux
CentOS7环境下安装MySQL5.6
CentOS7环境下安装MySQL5.6
194 0
|
2月前
|
缓存 负载均衡 应用服务中间件
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
67 1
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
|
2天前
|
关系型数据库 MySQL Linux
centos7安装mysql-带网盘安装包
centos7安装mysql-带网盘安装包
29 2
|
9天前
|
网络协议
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
11 0
|
9天前
|
关系型数据库 MySQL Linux
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
44 0
|
15天前
|
IDE Linux 开发工具
CentOS7.4+REDHAWK2.3.1安装教程——折腾篇
CentOS7.4+REDHAWK2.3.1安装教程——折腾篇
18 0
|
20天前
|
Linux Shell 开发工具
CentOS8中Docker安装及部署
CentOS8中Docker安装及部署
67 0

热门文章

最新文章