


Essential security settings for Linux servers, recommended collection! ! !
#I finally bought a server, but it would be really bad if it was hacked by a hacker due to my own negligence!
The following will tell you some simple methods to improve the security factor of the server. This is how my cloud server is configured. Yes, although it is a bit troublesome, I feel more at ease.
Modify ssh login configuration
Open the ssh configuration file
vim /etc/ssh/sshd_config#修改以下几项Port 10000#更改SSH端口,最好改为10000以上,别人扫描到端口的机率也会下降。防火墙要开放配置好的端口号,如果是阿里云服务器,你还需要去阿里云后台配置开发相应的端口才可以,否则登不上哦!如果你觉得麻烦,可以不用改 Protocol 2#禁用版本1协议, 因为其设计缺陷, 很容易使密码被黑掉。 PermitRootLogin no#尝试任何情况先都不允许 Root 登录. 生效后我们就不能直接以root的方式登录了,我们需要用一个普通的帐号来登录,然后用su来切换到root帐号,注意 su和su - 是有一点小小区别的。关键在于环境变量的不同,su -的环境变量更全面。 PermitEmptyPasswords no#禁止空密码登陆。
Finally needed Restart the sshd service
service sshd restart
Prohibit the system from responding to any ping requests from external/internal
echo “1”> /proc/sys/net/ipv4/icmp_echo_ignore_all
The default value is 0
用户管理
下面是基本的用户管理命令
查看用户列表:cat /etc/passwd查看组列表:cat /etc/group查看当前登陆用户:who查看用户登陆历史记录:last
一般需要删除系统默认的不必要的用户和组,避免被别人用来爆破:
userdel syncuserdel shutdown# 需要删除的多余用户共有:sync shutdown halt uucp operator games gophergroupdel admgroupdel games# 需要删除的多余用户组共有:adm lp games dip
Linux 中的帐号和口令是依据 /etc/passwd 、/etc/shadow、 /etc/group 、/etc/gshadow 这四个文档的,所以需要更改其权限提高安全性:
chattr +i /etc/passwdchattr +i /etc/shadowchattr +i /etc/groupchattr +i /etc/gshadow
如果还原,把 +i 改成 -i , 再执行一下上面四条命令。另外,搜索公众号Linux中文社区后台回复“私房菜”,获取一份惊喜礼包。
注:i 属性:不允许对这个文件进行修改,删除或重命名,设定连结也无法写入或新增数据!只有 root 才能设定这个属性。
创建新用户
创建新用户命令:adduser username
更改用户密码名:passwd username
个人用户的权限只可以在本 home 下有完整权限,其他目录要看别人授权。而经常需要 root 用户的权限,这时候 sudo 可以化身为 root 来操作。我记得我曾经 sudo 创建了文件,然后发现自己并没有读写权限,因为查看权限是 root 创建的。Linux 系统命令还是很重要的,120 个《 必知必会的 Linux 系统常用命令 》,推荐大家看看。
sudoers 只有只读的权限,如果想要修改的话,需要先添加 w 权限:chmod -v u+w /etc/sudoers 然后就可以添加内容了,在下面的一行下追加新增的用户:wq 保存退出,这时候要记得将写权限收回:chmod -v u-w /etc/sudoers
赋予 root 权限
方法一:修改 /etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉
## Allows people in group wheel to run all commands# 去掉下面一句的前面的注释 # %wheel ALL=(ALL) ALL# 然后修改用户,使其属于root组(wheel),命令如下:# usermod -g root uusama
修改完毕,现在可以用 uusama 帐号登录,然后用命令 su – ,即可获得 root 权限进行操作。
方法二(推荐):修改 /etc/sudoers 文件,找到下面一行,在 root 下面添加一行,如下所示:
## Allow root to run any commands anywhereroot ALL=(ALL) ALLuusama ALL=(ALL) ALL
修改完毕,现在可以用 uusama 帐号登录,然后用命令 sudo -s ,即可获得 root 权限进行操作。
方法三:修改 /etc/passwd 文件,找到如下行,把用户 ID 修改为 0 ,如下所示:
uusama:x:500:500:tommy:/home/uusama:/bin/bash# 修改后如下uusama:x:0:500:tommy:/home/uusama:/bin/bash
保存,用 uusama 账户登录后,直接获取的就是 root 帐号的权限。
The above is the detailed content of Essential security settings for Linux servers, recommended collection! ! !. For more information, please follow other related articles on the PHP Chinese website!

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.

The core components of the Linux system include the kernel, file system, and user space. 1. The kernel manages hardware resources and provides basic services. 2. The file system is responsible for data storage and organization. 3. Run user programs and services in the user space.

Maintenance mode is a special operating level entered in Linux systems through single-user mode or rescue mode, and is used for system maintenance and repair. 1. Enter maintenance mode and use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can check and repair the file system and use the command "fsck/dev/sda1". 3. Advanced usage includes resetting the root user password, mounting the file system in read and write mode and editing the password file.

Maintenance mode is used for system maintenance and repair, allowing administrators to work in a simplified environment. 1. System Repair: Repair corrupt file system and boot loader. 2. Password reset: reset the root user password. 3. Package management: Install, update or delete software packages. By modifying the GRUB configuration or entering maintenance mode with specific keys, you can safely exit after performing maintenance tasks.

Linux network configuration can be completed through the following steps: 1. Configure the network interface, use the ip command to temporarily set or edit the configuration file persistence settings. 2. Set up a static IP, suitable for devices that require a fixed IP. 3. Manage the firewall and use the iptables or firewalld tools to control network traffic.

Maintenance mode plays a key role in Linux system management, helping to repair, upgrade and configuration changes. 1. Enter maintenance mode. You can select it through the GRUB menu or use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can perform file system repair and system update operations. 3. Advanced usage includes tasks such as resetting the root password. 4. Common errors such as not being able to enter maintenance mode or mount the file system, can be fixed by checking the GRUB configuration and using the fsck command.

The timing and reasons for using Linux maintenance mode: 1) When the system starts up, 2) When performing major system updates or upgrades, 3) When performing file system maintenance. Maintenance mode provides a safe and controlled environment, ensuring operational safety and efficiency, reducing impact on users, and enhancing system security.

Indispensable commands in Linux include: 1.ls: list directory contents; 2.cd: change working directory; 3.mkdir: create a new directory; 4.rm: delete file or directory; 5.cp: copy file or directory; 6.mv: move or rename file or directory. These commands help users manage files and systems efficiently by interacting with the kernel.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment
