/etc/sudoers 文件格式解析

在Linux和Unix-like操作系统中,特权分离是重要的安全概念。本文详细介绍了如何正确、安全地获取root权限,重点关注编辑/etc/sudoers文件。讨论了直接登录root、使用su和sudo三种方法,并详细阐述了sudoers文件的修改,包括使用visudo、用户权限行、组权限行和自定义规则的设置。文章还提供了给用户分配sudo权限和创建别名的步骤。
摘要由CSDN通过智能技术生成

Introduction

Privilege separation is one of the fundamental security paradigms implemented in Linux and Unix-like operating systems. Regular users operate with limited privileges in order to reduce the scope of their influence to their own environment, and not the wider operating system.

A special user, called root, has super-user privileges. This is an administrative account without the restrictions that are present on normal users. Users can execute commands with super-user or root privileges in a number of different ways.

In this article, we will discuss how to correctly and securely obtain root privileges, with a special focus on editing the /etc/sudoers file.

We will be completing these steps on an Ubuntu 20.04 server, but most modern Linux distributions such as Debian and CentOS should operate in a similar manner.

This guide assumes that you have already completed the initial server setup discussed here. Log into your server as regular, non-root user and continue below.

Note: This tutorial goes into depth about privilege escalation and the sudoers file. If you just want to add sudo privileges to a user, check out our How To Create a New Sudo-enabled User quickstart tutorials for Ubuntu and CentOS.

How To Obtain Root Privileges

There are three basic ways to obtain root privileges, which vary in their level of sophistication.

Logging In As Root

The simplest and most straightforward method of obtaining root privileges is to directly log into your server as the root user.

If you are logging into a local machine (or using an out-of-band console feature on a virtual server), enter root as your username at the login prompt and enter the root password when asked.

If you are logging in through SSH, specify the root user prior to the IP address or domain name in your SSH connection string:

 
  1. ssh root@server_domain_or_ip

Copy

If you have not set up SSH keys for the root user, enter the root password when prompted.

Using su to Become Root

Logging in directly as root is usually not recommended, because it is easy to begin using the system for non-administrative tasks, which is dangerous.

The next way to gain super-user privileges allows you to become the root user at any time, as you need it.

We can do this by invoking the su command, which stands for “substitute user”. To gain root privileges, type:

 
  1. su

Copy

You will be prompted for the root user’s password, after which, you will be dropped into a root shell session.

When you have finished the tasks which require root privileges, return to your normal shell by typing:

 
  1. exit

Copy

Using sudo to Execute Commands as Root

The final, way of obtaining root privileges th

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HeathXian

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值