Linux系統調優及安全設置 linux
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup <<-備份系統自帶yum源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo <<—國內使用阿里雲yum源速度比較快 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo 注:鏡像官方網址http://mirrors.aliyun.com/ 若有自建yum倉能夠更改爲自建yum倉地址信息
永久關閉(須要重啓系統) sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 臨時關閉(無需重啓) setenforce 0 數字0表示Premissive,即給出警告提示,不會阻止操做,至關於disabled 數字1表示Enfocing,即表示SELinux爲開啓狀態 getenforce <<-查看selinux當前狀態
/etc/init.d/iptables stop <<-關閉iptables服務 /etc/init.d/iptables status <<-查看iptables狀態 chkconfig iptables off <<—開機啓動關閉
chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash <<-關閉服務 chkconfig --list|grep 3:on <<-檢查開機啓動的服務
cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori echo 'LANG="zh_CN.UTF-8"' >/etc/sysconfig/i18n source /etc/sysconfig/i18n echo $LANG
useradd mmod echo 123456|passwd --stdin mmod \cp /etc/sudoers /etc/sudoers.ori echo "mmod ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers tail -1 /etc/sudoers visudo -c
echo '#time sync by mmod at 2015-2-1' >>/var/spool/cron/root echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root crontab -l 注:集羣中有時間服務器,更改爲時間服務器地址
設置閒置帳號超時時間
echo 'export TMOUT=300' >>/etc/profile
命令行歷史記錄數 echo 'export HISTSIZE=5' >>/etc/profile echo 'export HISTFILESIZE=5' >>/etc/profile tail -3 /etc/profile ./etc/profile
echo '* - nofile 65535' >>/etc/security/limits.conf tail -1 /etc/security/limits.conf
cat >>/etc/sysctl.conf<<EOF net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_keepalive_time = 600 net.ipv4.ip_local_port_range = 4000 65000 net.ipv4.tcp_max_syn_backlog = 16384 net.ipv4.tcp_max_tw_buckets = 36000 net.ipv4.route.gc_timeout = 100 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1 net.core.somaxconn = 16384 net.core.netdev_max_backlog = 16384 net.ipv4.tcp_max_orphans = 16384 #如下參數是對iptables防火牆的優化,防火牆不開會提示,能夠忽略不理。 net.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_tcp_timeout_established = 180 net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60 net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120 EOF sysctl –p <<-配置完成後查看
yum install lrzsz nmap tree dos2unix nc -y
centos 5版本 find /var/spool/clientmqueue/ -type f | xargs rm -f centos 6.x版本 find /var/spool/postfix/maildrop/ -type f | xargs rm -f 寫成腳本,作定時任務 mkdir -p /server/scripts/ echo "find /var/spool/postfix/maildrop/ -type f | xargs rm -f " > /server/scripts/del_mailfile.sh echo "00 00 * * * /bin/bash /server/scripts/del_mailfile.sh > /dev/null 2>&1"
[root@server1 ~]# > /etc/issue [root@server1 ~]# > /etc/issue.net [root@server1 ~]# cat /etc/issue.net [root@server1 ~]# cat /etc/issue
chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab
使用lsattr 進行查看,chattr -i進行解鎖
先利用/sbin/grub-md5-crypt 產生一個MD5密鑰串,命令以下: [root@m01 ~]# /sbin/grub-md5-crypt Password: Retype password: $1$SQxvZ/$AXRHUbkNy9EkDHtmoEoQS0 修改grub.conf文件,命令以下: [root@m01 ~]# vim /etc/grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/sda3 # initrd /initrd-[generic-]version.img #boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu passwd --md5 $1$SQxvZ/$AXRHUbkNy9EkDHtmoEoQS0 #注意:password要加在splashimage和title之間,不然沒法生效 title CentOS 6 (2.6.32-696.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=33ec961c-16e1-4234-bdbf-644bfdabf1eb rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LV
echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf sysctl -p
拓展:設置特定ip能夠ping
iptables -t filter -I INPUT -p icmp --icmp-type 8 -i eth0 -s 10.0.0.0/24 -j ACCEPT
查看相關軟件的版本號,命令以下: [root@m01 ~]# rpm -qa openssl openssh bash openssl-1.0.1e-57.el6.x86_64 bash-4.1.2-48.el6.x86_64 openssh-5.3p1-122.el6.x86_64 升級已知漏洞的軟件版本到最新,命令以下: yum install openssl openssh bash -y
1 修改默認文件路徑 2 vim /etc/ssh/sshd_config 3 4 修改的參數 5 port #端口 6 PermitEmptyPasswords #是否容許密碼爲空的用戶遠程登陸 7 PermitRootLogin #是否容許root登陸 8 UseDNS #指定sshd是否應該對遠程主機名進行反向解析,以檢查主機名是否與其IP地址真實對應。默認yes.建議改爲no ,不然可能會致使SSH鏈接很慢。 9 GSSAPIAuthentication no #解決linux之間使用SSH遠程鏈接慢的問題 10 ListenAddress #監聽指定的IP地址 11 12 批量操做: 13 sed -ir '13 iPort 55666\nPermitRootLogin no\nPermitEmptyPasswords no\nUseDNS no\nGSSAPIAuthentication no' /etc/ssh/sshd_config