[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