[root@oldboy ~]# useradd oldboy [root@oldboy ~]# id oldboy uid=500(oldboy) gid=500 (oldboy) groups=500(oldboy) [root@oldboy ~]# echo 123456lpasswd --stdin oldboy Changing password for user oldboy. passwd: all authentication tokens updated successfully.
[root@oldboy ~]# visudo [root@oldboy ~]# grep -w oldboy /etc/sudoers oldboy ALL=(ALL) NOPASSWD: ALL 遠程鏈接直接用oldboy 棄用root登陸,改用oidboy用戶登陸。 [oldboy@oldboy ~]$ whoami oldboy [oldboy@oldboy ~]$ sudo su - [root@oldboy ~]# whoami root
centos6 臨時關閉: /etc/init.d/iptables stop 永久關閉: chkconfig iptables off 關閉後檢查: /etc/init.d/iptables status chkconfig --list iptables centos7 臨時關閉:systemctl stop firewalld.service 永久關閉: systemctl disable firewalld.service 關閉後檢查: systemctl is-active firewalld.service
備份/etc/ssh/ssh_config cp /etc/ssh/ssh_config{,.bak} vim /etc/ssh/ssh_config ###by xly#2018-11-24## Port 52113 #設置10000以上的端口 PermitRootLogin no #禁止root遠程登陸 PermitEmptyPasswords no #禁止空密碼登陸 UseDNS no #不使用DNS解析 GSSAPIAuthentication no #Xshell鏈接慢的解決配置 ###by xly#2018-11-24## 把監聽網段改掉,即0.0.0.0改成內網網段,例如10.0.0.0 grep -i listen /etc/ssh/ssh_config
①永久生效,須要重啓計算機 更改配置文件/etc/selinux/config vim /etc/selinux/config把SELINUX=enforcing改爲SELINUX=disable或者 sed -i 's#SELINUX=enforcing#SELINUX=disable#g' /etc/selinux/config ②臨時生效 設置:setenforce 0 查看:getenforce 結果爲Permissive
設置運行級別:grep 3:initdefault /etc/inittab 查看運行級別:runlevel
linux系統要開啓的開機自啓動服務:sshd、rsyslog、network、crond、sysstat chkconfig --list|grep "3:on" 首先查看有哪些服務開機自啓動 思路: 關掉不須要的 chkconfig --list|grep "3:on"|egrep -v "sshd|rsyslog|network|cron|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash 優化: chkconfig --list|grep "3:on"|grep -vE "sshd|rsyslog|network|cron|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash 關閉全部,開啓須要的 全關:chkconfig --list|grep "3:on"|awk '{print "chkconfig",$1,"off"}'|bash 開須要的:chkconfig --list|egrep "sshd|rsyslog|network|cron|sysstat"|awk '{print "chkconfig",$1,"on"}'|bash
centos6 修改/etc/sysconfig/i18n vim /etc/sysconfig/i18n把LANG="zh_CN.UTF-8"放進去 查看結果:cat /etc/sysconfig/i18n 使之生效:source /etc/sysconfig/i18n或者. /etc/sysconfig/i18n centos7 修改 /etc/locale.conf vim /etc/locale.conf 把 LANG="zh_CN.UTF-8"放進去 查看結果:cat /etc/locale.conf 使之生效:source /etc/locale.conf或者. /etc/locale.conf
①驗證時間同步服務器是否可用 /usr/sbin/ntpdate ntp2.aliyun.com ②設置定時任務 echo 'time sync by liyang at 2019-3-30' >>/var/spool/cron/root echo '*/5 * * * * /usr/sbin/ntpdate ntp2.aliyun.com >/dev/null 2>&1' >>/var/spool/cron/root centos7 /usr/bin/timedatectl # 安裝 yum install chrony # 啓用 systemctl start chronyd systemctl enable chronyd # 設置亞洲時區 timedatectl set-timezone Asia/Shanghai # 啓用NTP同步 timedatectl set-ntp yes
echo 'export TIMEOUT=300' >>/etc/profile echo 'export HISTSIZE=5' >>/etc/profile echo 'export HISTFILESIZE=5' >>/etc/profile tail -3 /etc/profile source /etc/profile 使配置文件生效
加鎖 chattr +i /etc/passwd /etc/shadow /etc/group /etc/inittab /etc/fstab /etc/sudoers 查看加鎖的文件 lsattr 還能夠把chattr命令移走:mv /usr/bin/chattr /opt/oldboy 想用的時候移回來:mv /opt/oldboy /usr/bin/chattr
能夠選擇不優化,加框的是有用的
linux
[root@oldboy ~]# /sbin/grub-md5-crypt Password: Retype password: $1s.Fv.q/$eCasAokskqxvw0ow37hJr1 vi /etc/grub.conf password --md5 $1s.Fv.q/$eCasAokskqxvw0ow37hJr1 注意:password要加在aplashimage和title之間,不然可能沒法生效
查看文件信息:cat /etc/issue 清除文件信息:>/etc/issue.net >/etc/issue
[rootooldboy ~]# echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf [rootooldboy ~]#sysctl -p 本身也沒辦法調試了,Iptables指定內網能夠Ping,外網不能ping.
①文件永久生效 echo ‘* - nofile 65535’ >>/etc/security/limits.conf tail -1 /etc/security/limits.conf ②臨時生效 ulimit -SHn 65535 能夠追加到/etc/rc.local每次開機自啓動 echo >>/etc/rc.local<<EOF #-S user the 'soft' resource limit #-H user the 'hard' resource limit #-n the maximum number of open file derscriptors ulimit -SHn 65535 #-s the maximum stack size ulimit -s 65535 EOF
vim /etc/sysctl.conf添加以下內容: 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 = 259909 I 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_tco_timeout_fin_wait = 120 執行svsctl-p生效
首先查看先關軟件版本號: rpm -qa openssl openssh bash 升級已知漏洞的軟件版本到最新 yum install openssl openssh bash -y yum update
①手動清理的方法以下: find /var/spool/postfix/maildrop/ -type f|xargs rm -f ②定時清理的方法:作定時任務 寫個腳本: echo "find /var/spool/postfix/maildrop/ -type f|xargs rm -f" >/server/scripts/del_file.sh 作定時任務 echo "00 00 * * * /bin/sh /server/scripts/del_file.sh >/dev/null 2>&1" >>/var/spoll/cron/root 查看作好的定時任務 corntab -l
都是內網IP
shell
rm -f /etc/yum.repos.d/* curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install net-tools vim tree htop iftop \ iotop lrzsz sl wget unzip telnet nmap nc psmisc \ dos2unix bash-completion bash-completion-extra sysstat \ rsync nfs-utils httpd-tools -y