


Recommended to collect! ! ! Essential security settings for Linux servers~

# It's too bad!
#########The following will tell you some simple methods to improve the security factor of the server. My cloud server is configured in this way. 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, you need to restart the sshd service ######
service sshd restart######Prohibits the system from responding to any ping requests from external/internal sources######
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 , 再执行一下上面四条命令。
注:i 属性:不允许对这个文件进行修改,删除或重命名,设定连结也无法写入或新增数据!只有 root 才能设定这个属性。
创建新用户
创建新用户命令:adduser username
更改用户密码名:passwd username
个人用户的权限只可以在本 home 下有完整权限,其他目录要看别人授权。而经常需要 root 用户的权限,这时候 sudo 可以化身为 root 来操作。我记得我曾经 sudo 创建了文件,然后发现自己并没有读写权限,因为查看权限是 root 创建的。
sudoers 只有只读的权限,如果想要修改的话,需要先添加 w 权限:chmod -v u+w /etc/sudoers 然后就可以添加内容了,在下面的一行下追加新增的用户:wq 保存退出,这时候要记得将写权限收回:chmod -v u-w /etc/sudoers
牛逼啊!接私活必备的 N 个开源项目!赶快收藏
赋予 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 anywhere root ALL=(ALL) ALL uusama 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 Recommended to collect! ! ! Essential security settings for Linux servers~. For more information, please follow other related articles on the PHP Chinese website!

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.

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.


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

Atom editor mac version download
The most popular open source editor

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.

Dreamweaver CS6
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
