linux系統安全優化

linux系統安全優化

用戶賬號安全優化

1、禁用(鎖定)zhangsan用戶

passwd –l

[root@s2 ~]# passwd -l zhangsan

Locking password for user zhangsan.

passwd: Success

  直接修改shadow文件,密碼字符串前加!

[root@s2 ~]# vi /etc/shadow

zhangsan:!!:14724:0:99999:7:::

2、將不需要使用終端的用戶的登錄shell改爲/sbin/nologin

[root@s2 ~]# vi /etc/passwd

zhangsan:x:500:500::/home/zhangsan:/sbin/nologin

或者

[root@s2 ~]# usermod -s /sbin/nologin  zhangsan

3、限制用戶的密碼有效期

PASS_MAX_DAYS   30        //只對新建立的用戶有效

或者

[root@s2 ~]# chage -M 30 zhangsan   //只對已存在的用戶有效

4、指定用戶在下次登錄時必須修改密碼

[root@s2 ~]# chage -d 0 zhangsan

或者

zhangsan:!!:0:0:30:7:::     第三列改爲0

5、限制密碼的最小長度

[root@s2 ~]# vi /etc/pam.d/system-auth

password    requisite    pam_cracklib.so try_first_pass retry=3

6、限制記錄命令歷史的條數

[root@s2 ~]# vi /etc/profile

HISTSIZE=1000

7、設置超時自動註銷終端

[root@s2 ~]# vi /etc/profile

TMOUT=600

使用su  切換用戶身份

8、如何拒絕使用su – 切換用戶

[root@s2 ~]# vi /etc/pam.d/su

auth            required       pam_wheel.so use_uid

9、允許zhangsan使用su – 切換用戶

[root@s2 ~]# gpasswd -a zhangsan wheel

Adding user zhangsan to group wheel

使用sudo提升執行權限

1、授權用戶jerry可以以root權限執行ifconfig

jerry   ALL=/sbin/ifconfig       用戶主機=命令絕對路徑

2、通過別名定義一組命令,並授權tom用戶可以使用改組命令

Cmnd_Alias     SYSVCTRL=/sbin/service,/bin/kill,/bin/killall

tom     ALL=SYSVCTRL

3、授權wheel組的用戶不需驗證密碼即可執行名令

%wheel  ALL=(ALL)       NOPASSWD: ALL

*代表通配符!表示取反

4、爲sudo啓用日誌功能,將記錄寫入/var/log/sudo文件中

Defaults logfile ="/var/log/sudo"

local2.debug                               /var/log/sudo   修改系統日誌配置文件

[root@s2 ~]# service syslog restart   //重啓syslog系統服務

Shutting down kernel logger:                              [ OK  ]

Shutting down system logger:                              [ OK  ]

Starting system logger:                                  [  OK  ]

Starting kernel logger:                                  [  OK  ]

5、使用sudo執行命令

tom查看自己被授權使用命令,並使用sudo執行命令

[tom@s2 ~]$ sudo -l

Password:

User tom may run the following commands on this host:

(root)/sbin/service

[tom@s2 ~]$ sudo /sbin/service httpd start

文件和文件系統安全優化

1、鎖定不希望改改的系統文件

[root@s2 ~]# chattr +i /etc/services  /etc/passwd/boot/grub/grub.conf

2、解除/etc/passwd文件中的+i屬性鎖定

[root@s2 ~]# chattr -i /etc/passwd

3、關閉不必要的系統服務

[root@s2 ~]# service bluetooth stop

[root@s2 ~]# chkconfig bluetooth off

4、禁止普通用戶執行init.d目錄中的腳本

[root@s2 ~]# chmod -R o-rwx /etc/init.d/

或者

[root@s2 ~]# chmod  750 /etc/init.d/

5、禁止普通用戶執行poweroffhalltreboot 控制檯程序

[root@s2 console.apps]# tar -jcpvf /etc/conhlp.pw.tar.bz2poweroff halt reboot --remove

poweroff

halt

reboot

6、查找系統中設置了set-uidset-gid權限的文件,並結合”-exec”選項顯示這些文件的詳細權限屬性。

[root@s2 console.apps]# find / -type f -perm +600 -execls -lh {} \

7、去除程序文件的suid/sgid爲權限

drwsr-sr-t 2 root root  4096 Mar 18 18:20 aa

[root@s2 ~]# chmod a-s aa

系統引導和登錄安全優化

1、阻止用戶通過Ctrl+Alt+Del

[root@s2 ~]# vi /etc/inittab

#ca::ctrlaltdel:/sbin/shutdown -t3 -r now

2、在grup.conf文件中設置明文密碼

[root@s2 ~]# vi /boot/grub/grub.conf

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

password 123456

title Red Hat Enterprise Linux Server (2.6.18-8.el5)

       root (hd0,0)

       kernel /vmlinuz-2.6.18-8.el5ro root=/dev/VolGroup00/LogVol00 rhgb quiet

       initrd/initrd-2.6.18-8.el5.img

3、在grup.cof文件中設置md5加密的密碼字符串

[root@s2 ~]# grub-md5-crypt

Password:

Retype password:

$1$x.20Z0$hY6SYWzlbDBnir./dS87o0

[root@s2 ~]# vi /boot/grub/grub.conf

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

password $1$x.20Z0$hY6SYWzlbDBnir./dS87o0

title Red Hat Enterprise Linux Server (2.6.18-8.el5)

       root (hd0,0)

       kernel /vmlinuz-2.6.18-8.el5ro root=/dev/VolGroup00/LogVol00 rhgb quiet

       initrd/initrd-2.6.18-8.el5.img

4、禁用tty4-tty6終端

[root@s2 ~]# vi /etc/inittab

1:2345:respawn:/sbin/mingetty tty1

2:2345:respawn:/sbin/mingetty tty2

3:2345:respawn:/sbin/mingetty tty3

#4:2345:respawn:/sbin/mingetty tty4

#5:2345:respawn:/sbin/mingetty tty5

#6:2345:respawn:/sbin/mingetty tty6

5、禁止root用戶從tty2-tty3終端

[root@s2 ~]# vi /etc/securetty

#tty2

#tty3

6、將登錄提示內容修改爲“Welcome to Server”

root@s2 ~]# vi /etc/issue

Welcome to Server

7、禁止除了root以外的用戶從tty1終端上登錄系統

[root@s2 ~]# vi /etc/pam.d/login

account    required     pam_access.so  //pam配置文件login中添加認證支持

[root@s2 ~]# vi /etc/security/access.conf

-:ALL EXCEPT root:tty1

8、禁止root用戶從192.168.1.0/24網絡登錄

[root@s2 ~]# vi /etc/pam.d/sshd

account    required    pam_access.so//添加pam配置文件sshd中添加認證支持

[root@s2 ~]# vi /etc/security/access.conf

- : root : 192.168.1.0/24

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章