Linux初始化工作

2015-07-29  本文已影响45人  Callback

1. 用户管理

1.1 建用户

adduser username

passwd username

1.2 将新建用户添加至wheel组

1.3 配置新建用户可使用sudo命令

1.4 删除不需要的用户,不需要的组

注意:不建议直接删除,当你需要某个用户时,自己重新添加会很麻烦。

#adm:x:3:4:adm:/var/adm:/sbin/nologin
#lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
#sync:x:5:0:sync:/sbin:/bin/sync
#shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
#halt:x:7:0:halt:/sbin:/sbin/halt
#uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
#operator:x:11:0:operator:/root:/sbin/nologin
#games:x:12:100:games:/usr/games:/sbin/nologin
#gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
#ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin #注释掉ftp匿名账号
#news:x:9:13:news:/etc/news:

2.修改SSH连接

出于安全考虑,SSH服务配置做以下方面修改

编辑/etc/ssh/sshd_config文件


Port 22 #自己定义一个端口
HostKey /etc/ssh/ssh_host_dsa_key #支持密钥登陆
PermitRootLogin no # 禁用root登陆
StrictModes yes # 采用putty等客户端登陆需要改成no

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

PasswordAuthentication no # 禁用密码登陆

调用ssh-keygen -t rsa生成密钥对,将公钥上id_rsa.pub上传至服务器~/.ssh目录,然后执行cat id_rsa.pub >> authorized_keys

注意,操作完成后,新开一个连接检测是否配置正常,不要关闭当前连接,否则你可能永远都连不上你的服务器了。。。。

3. 防火墙设置

3.1 禁止ping

echo 1 > /proc/sys/net/ipv4/icmp_echo_igore_all #开启
echo 0 > /proc/sys/net/ipv4/icmp_echo_igore_all #关闭
iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -j DROP

注意保存service iptables save和重启服务service iptables reload

4. 关闭selinux

/usr/sbin/setenforce 0  # 0立刻关闭 1立刻启用
echo "/usr/sbin/setenforce 0" >> /etc/rc.local # 加到系统默认启动里面

5. 关掉不必要的服务

chkconfig --list # 查看系统所有的服务是打开还是关闭
chkconfig 服务名 on # 设置随机启动
chkconfig 服务名 off # 设置不随机启动

6. 修改系统参数


**cat**
>>
/
etc/
sysctl.conf<<
eof     net.ipv4.tcp_syncookies =
 1
     net.ipv4.tcp_tw_reuse =
 1
     net.ipv4.tcp_tw_recycle =
 1
     net.ipv4.tcp_fin_timeout =
 30
     net.ipv4.tcp_keepalive_time =
 120
     net.ipv4.ip_local_port_range =
 10000
 65000
     net.ipv4.tcp_max_tw_buckets =
 8000
eofsysctl -
p

ulimit -
HSn 65535
**echo**
 -
ne "* soft nofile 65535* hard nofile 65535"
 >>
/
etc/
security/
limits.conf
上一篇 下一篇

猜你喜欢

热点阅读