1.證書登錄 變動默認的ssh服務端口等配置 api
建立證書:ssh-keygen -t rsa
配置:mv id_rsa.pub authorized_keys
編輯:vi /etc/ssh/sshd_config 緩存
Protocol 2048
SyslogFacility AUTHPRIV
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
PasswordAuthentication no #同值 UsePAM
ChallengeResponseAuthentication no #同值 UsePAM
UsePAM no #同值上面兩項
UseDNS no
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
X11Forwarding yesbash
2.操做歷史時間配置服務器
vi .bashrc
HISTFILESIZE=200
HISTSIZE=100
HISTTIMEFORMAT="%Y%m%d-%H%M%S: " #or HISTTIMEFORMAT="%Y%m%d %T "
export HISTTIMEFORMAcookie
history -c 命令:清空history當前歷史命令的記錄
history -w 命令:當即更新history文件網絡
3.文件系統優化dom
修改ulimit -n 參數:默認是1024---該配置項是每一個進程能夠打開的文件數.
一、vi /etc/profile #ulimit -n 65535 #source /etc/profile
二、修改/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
調整內核參數 vi /etc/sysctl.conf #sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_wmem = 8192 4336600 873200
net.ipv4.tcp_rmem = 32768 4336600 873200
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 786432 1048576 1572864
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.ip_local_port_range = 1024 65000
net.nf_conntrack_max = 655360 #默認65535 防火牆跟蹤表ssh
4.iptables配置tcp
規則被清除
iptables -F
iptables -X
設置chain默認策略
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT分佈式
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p tcp --dport 2048 -j ACCEPT #與sshd配置的端口相同
-A INPUT -p icmp -j DROP #不容許ping
-A INPUT -i lo -p all -j ACCEPT #容許loopback
-A INPUT -s 192.168.0.3 -p tcp --dport 2048 -j ACCEPT #控制源地址訪問這臺服務器的SSH
5.帳號加固:禁用root,管理用戶和用戶組
/etc/passwd
/etc/shadow
/etc/group
/etc/gshadow
*更改root名字
6.添加經常使用yum源 並升級到最新版本
CentOS 基礎(經常使用)的源:
http://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm
http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
CentOS 升級內核的源
http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
7.定時自動更新服務器時間 修改時區
ntpdate 1.pool.ntp.org
crontab -e
0 21 * * * ntpdate ntpdate 1.pool.ntp.org
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #命令tzselect
8.修改DNS信息
vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 114.114.114.114
9.ntsysv 關閉不經常使用服務
10.設置字符集爲英文(中文)
cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SUPPORTER="en_US.UTF-8:en_US:zh"
SYSFONT="latarcyrheb-sun16"
LANG="en_US.UTF-8"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
LC_ALL="en_US.UTF-8"
export LC_ALL
改登陸用戶的.bash_profile
export LANG=zh_CN.GB18030
export LANGUAGE=zh_CN.GB18030:zh_CN.GB2312:zh_CN
11.關閉多餘控制檯
vi /etc/init/start-ttys.conf #tty[1-3]
12.關閉ipv6
/etc/sysconfig/network
echo "alias net-pf-10 off" >> /etc/modprobe.d/ECS.conf
echo "alias ipv6 off" >> /etc/modprobe.d/ECS.conf
/sbin/chkconfig --level 35 ip6tables off
13 隱藏服務器系統信息
mv /etc/issue /etc/issuebak
mv /etc/issue.net /etc/issue.netbak
1四、服務器禁止ping
vi /etc/rc.d/rc.local #在文件末尾增長下面這一行
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all #參數0表示容許 1表示禁止