


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!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Title: PHP script implementation of cross-server file transfer 1. Introduction In cross-server file transfer, we usually need to transfer files from one server to another. This article will introduce how to use PHP scripts to implement cross-server file transfer on Linux servers, and give specific code examples. 2. Preparation Before starting to write PHP scripts, we need to ensure that the following environment has been configured on the server: Install PHP: Install PHP on the Linux server and ensure that the PHP version meets the code requirements.

How to deploy a trustworthy web interface on a Linux server? Introduction: In today's era of information explosion, Web applications have become one of the main ways for people to obtain information and communicate. In order to ensure user privacy and information reliability, we need to deploy a trustworthy Web interface on the Linux server. This article will introduce how to deploy a web interface in a Linux environment and provide relevant code examples. 1. Install and configure the Linux server. First, we need to prepare a Li

How to optimize the performance and resource utilization of Linux servers requires specific code examples. Summary: Optimizing Linux server performance and resource utilization is the key to ensuring stable and efficient server operation. This article will introduce some methods to optimize Linux server performance and resource utilization, and provide specific code examples. Introduction: With the rapid development of the Internet, a large number of applications and services are deployed on Linux servers. In order to ensure the efficient and stable operation of the server, we need to optimize the performance and resource utilization of the server to achieve

Linux Server Security: Using Commands to Check System Vulnerabilities Overview: In today’s digital environment, server security is crucial. Timely detection and repair of known vulnerabilities can effectively protect servers from potential attack threats. This article will introduce some commonly used commands that can be used to check system vulnerabilities on Linux servers and provide relevant code examples. By using these commands correctly, you will be able to enhance the security of your server. Check for system updates: Before you start checking for vulnerabilities, make sure your system has

With the development of Internet technology, more and more enterprises and individuals choose to use Linux servers to host and manage their applications and websites. However, as the number of servers increases, server failures and security issues become an urgent task. This article will explore the causes of Linux server failures and how to manage and protect the system healthily. First, let's take a look at some common reasons that can cause Linux servers to malfunction. Firstly, hardware failure is one of the most common reasons. For example, the server is overheating,

Providing Stronger Web Interface Security: Key Practices for Linux Servers Web interface security has become increasingly important in today’s digital age. As more and more applications and services move to the cloud, server security protection is increasingly becoming a critical issue. As one of the most commonly used server operating systems, Linux's security protection is crucial. This article will introduce some key practices to help you provide stronger web interface security. Updating and maintaining operating systems and software Timely updates of operating systems and software are services

Linux server security practice: using command line tools for defense Introduction: As a Linux server administrator, we must always protect the security of the server. In daily work, using command line tools to defend servers is a simple and efficient method. This article will introduce some commonly used command line tools and give corresponding code examples to help administrators strengthen server security. 1. Firewall settings Firewall is an important tool to protect the server from malicious attacks. The commonly used firewall tool in Linux systems is i

Linux Server Security Hardening: Configure and Optimize Your System Introduction: In today's environment of increasing information security threats, protecting your Linux server from malicious attacks and unauthorized access has become critical. To harden your system security, you need to take a series of security measures to protect your server and the sensitive data stored on it. This article will cover some key configuration and optimization steps to improve the security of your Linux server. 1. Update and manage software packages. Installing the latest software packages and updates is essential for maintaining the system.
