linux 服务器安全设置教程

2019-10-15 19:53:46刘景俊

  # want to make to /etc/issue here or you will lose them when you reboot.

  # echo “” 》 /etc/issue

  # echo “$R” 》》 /etc/issue

  # echo “Kernel $(uname -r) on $a $(uname -m)” 》》 /etc/issue

  # cp -f /etc/issue /etc/issue.net

  # echo 》》 /etc/issue

  然后,进行如下操作:

  [root@server /]# rm -f /etc/issue

  [root@server /]# rm -f /etc/issue.net

  [root@server /]# touch /etc/issue

  [root@server /]# touch /etc/issue.net

  8.设置Grub密码

  [root@server share]# grub-md5-crypt

  Password: //输入密码

  Retype password: //输入确认密码

  $1$LlZDJ/$VxlsjlcR9vvWcI/YRHPpm0

  vim /boot/grub/grub.conf

  添加一行:password $1$LlZDJ/$VxlsjlcR9vvWcI/YRHPpm0

  三、限制网络访问

  1.NFS访问如果您使用NFS网络文件系统服务,应该确保您的/etc/exports具有最严格的访问权限设置,也就是意味着不要使用任何通配符、不允许root写权限并且只能安装为只读文件系统。编辑文件/etc/exports并加入如下两行。

  /dir/to/export host1.mydomain.com(ro,root_squash)

  /dir/to/export host2.mydomain.com(ro,root_squash)

  /dir/to/export 是您想输出的目录,host.mydomain.com是登录这个目录的机器名,ro意味着mount成只读系统,root_squash禁止root写入该目录。为了使改动生效,运行如下命令。

  [root@server /]# /usr/sbin/exportfs -a

  2.Inetd设置

  首先要确认/etc/inetd.conf的所有者是root,且文件权限设置为600。设置完成后,可以使用“stat”命令进行检查。

  [root@server /]# chmod 600 /etc/inetd.conf

  然后,编辑/etc/inetd.conf禁止以下服务。

  ftp telnet shell login exec talk ntalk imap pop-2 pop-3 finger auth

  如果您安装了ssh/scp,也可以禁止掉Telnet/FTP。为了使改变生效,运行如下命令:

  [root@server /]# killall -HUP inetd

  默认情况下,多数Linux系统允许所有的请求,而用TCP_WRAPPERS增强系统安全性是举手之劳,您可以修改/etc/hosts.deny和 /etc/hosts.allow来增加访问限制。例如,将/etc/hosts.deny设为“ALL: ALL”可以默认拒绝所有访问。然后在/etc/hosts.allow文件中添加允许的访问。例如,“sshd: 192.168.1.10/255.255.255.0 gate.openarch.com”表示允许IP地址192.168.1.10和主机名gate.openarch.com允许通过SSH连接。

  配置完成后,可以用tcpdchk检查:

  [root@server /]# tcpdchk

  tcpchk是TCP_Wrapper配置检查工具,它检查您的tcp wrapper配置并报告所有发现的潜在/存在的问题。

  3.登录终端设置

  /etc/securetty文件指定了允许root登录的tty设备,由/bin/login程序读取,其格式是一个被允许的名字列表,您可以编辑/etc/securetty且注释掉如下的行。