Linux System Security Settings Shell script

Source: Internet
Author: User

Linux System Security Settings Shell script

This script has been widely used in a large media website system and added some security settings that were not previously imagined. Copy it and save it as a Shell file, such as security. sh. upload it to the Linux server. Execute sh security. sh to use this script!

Note: The script is for reference only. We recommend that you modify it based on your actual needs. Do not use it blindly!

 
  1. #!/bin/sh
  2. # desc: setup linux system security
  3. # author:coralzd
  4. #account setup
  5. passwd -l xfs
  6. passwd -l news
  7. passwd -l nscd
  8. passwd -l dbus
  9. passwd -l vcsa
  10. passwd -l games
  11. passwd -l nobody
  12. passwd -l avahi
  13. passwd -l haldaemon
  14. passwd -l gopher
  15. passwd -l ftp
  16. passwd -l mailnull
  17. passwd -l pcap
  18. passwd -l mail
  19. passwd -l shutdown
  20. passwd -l halt
  21. passwd -l uucp
  22. passwd -l operator
  23. passwd -l sync
  24. passwd -l adm
  25. passwd -l lp
  26. # chattr /etc/passwd /etc/shadow
  27. chattr +i /etc/passwd
  28. chattr +i /etc/shadow
  29. chattr +i /etc/group
  30. chattr +i /etc/gshadow
  31. # add continue input failure 3 ,passwd unlock time 5 minite
  32. sed -i 's#auth required pam_env.so#auth required pam_env.sonauth required pam_tally.so onerr=fail deny=3 unlock_time=300nauth required /lib/security/$ISA/pam_tally.so onerr=fail deny=3 unlock_time=300#' /etc/pam.d/system-auth
  33. # system timeout 5 minite auto logout
  34. echo "TMOUT=300" >>/etc/profile
  35. # will system save history command list to 10
  36. sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile
  37. # enable /etc/profile go!
  38. source /etc/profile
  39. # add syncookie enable /etc/sysctl.conf
  40. echo "net.ipv4.tcp_syncookies=1" >> /etc/sysctl.conf
  41. sysctl -p # exec sysctl.conf enable
  42. # optimizer sshd_config
  43. sed -i "s/#MaxAuthTries 6/MaxAuthTries 6/" /etc/ssh/sshd_config
  44. sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config
  45. # limit chmod important commands
  46. chmod 700 /bin/ping
  47. chmod 700 /usr/bin/finger
  48. chmod 700 /usr/bin/who
  49. chmod 700 /usr/bin/w
  50. chmod 700 /usr/bin/locate
  51. chmod 700 /usr/bin/whereis
  52. chmod 700 /sbin/ifconfig
  53. chmod 700 /usr/bin/pico
  54. chmod 700 /bin/vi
  55. chmod 700 /usr/bin/which
  56. chmod 700 /usr/bin/gcc
  57. chmod 700 /usr/bin/make
  58. chmod 700 /bin/rpm
  59. # history security
  60. chattr +a /root/.bash_history
  61. chattr +i /root/.bash_history
  62. # write important command md5
  63. cat > list << "EOF" &&
  64. /bin/ping
  65. /bin/finger
  66. /usr/bin/who
  67. /usr/bin/w
  68. /usr/bin/locate
  69. /usr/bin/whereis
  70. /sbin/ifconfig
  71. /bin/pico
  72. /bin/vi
  73. /usr/bin/vim
  74. /usr/bin/which
  75. /usr/bin/gcc
  76. /usr/bin/make
  77. /bin/rpm
  78. EOF
  79. for i in `cat list`
  80. do
  81. if [ ! -x $i ];then
  82. echo "$i not found,no md5sum!"
  83. else
  84. md5sum $i >> /var/log/`hostname`.log
  85. fi
  86. done
  87. rm -f list

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.