찾다
시스템 튜토리얼리눅스Debian 12의 사용자에게 추가, 삭제 및 권한을 부여하는 방법

In Debian, managing user privileges and administrative access is crucial for maintaining a secure and efficient system. By granting users the ability to execute administrative tasks without relying on the root account, you can enhance security, control access to sensitive operations, and maintain an audit trail of user activity. This detailed guide walks you through the steps to add, delete, and grant sudo privileges to users in Debian Linux.

Whether you're setting up a new Debian system or need to manage user accounts on an existing installation, this step-by-step tutorial is designed to provide clear instructions and explanations that even beginners can follow.

By the end of this guide, you'll have a solid understanding of how to create new user accounts, grant them sudo access, and remove users when necessary.

Before getting into the topic of adding, deleting, and granting sudo privileges to users in Debian, it's essential to understand what sudo is and the advantages it offers.

Table of Contents

1. What is Sudo?

The sudo (Superuser Do) command in Linux and Unix-like systems allows authorized users to execute commands with the privileges of the superuser or another user. It enables users to perform administrative tasks without logging in as the root user permanently.

The primary purpose of sudo is to provide a safer and more controlled approach to system administration. Instead of granting full root access to users, sudo enables privilege separation, limiting the scope of elevated privileges to specific commands or operations.

2. Advantages of Sudo Users

Here are some key aspects regarding sudo and the advantages of having a sudo user:

1. Privilege Separation

By default, Linux systems have a root user account with full administrative privileges. However, logging in as the root user can be risky because any command executed has unrestricted access to the entire system.

Sudo provides a way to separate regular user accounts from privileged tasks, allowing users to perform administrative actions only when needed.

2. Limited Privilege Escalation

Sudo allows specific users or groups to execute specific commands with elevated privileges. This provides a controlled and auditable way to grant temporary administrative access to trusted users.

Users can execute individual commands or a series of commands with sudo by authenticating themselves with their own password, rather than the root password.

3. Auditing and Accountability

Sudo logs all executed commands, providing an audit trail for system administrators. This audit trail helps track who executed which commands and when, enhancing system security and accountability.

The logs generated by sudo can be analyzed to investigate security incidents, troubleshoot issues, and monitor user activity.

4. Fine-Grained Access Control

With sudo, system administrators can define granular access control policies for different users or groups. This allows them to specify precisely which commands or operations each user can perform with elevated privileges.

Access control can be customized based on factors such as user roles, specific systems or services, and even specific command options.

5. Reduced Risk of Accidental Damage

Using sudo helps mitigate the risk of accidental damage caused by executing privileged commands. With sudo, users need to deliberately prefix a command with sudo to run it with elevated privileges, reducing the likelihood of unintentional system modifications or deletions.

It provides an extra layer of safety by prompting users for authentication before executing privileged operations, ensuring they are aware of the consequences of their actions.

6. Collaboration and Delegation

Sudo facilitates collaboration among system administrators by allowing them to delegate specific administrative tasks to other users without sharing the root password.

By assigning sudo privileges to trusted users, the workload can be distributed, and routine administrative tasks can be performed by designated individuals without requiring full root access.

In summary, having a sudo user provides a more secure and controlled approach to system administration. It enhances security, accountability, and flexibility by enabling limited privilege escalation, fine-grained access control, auditing, and delegation of administrative tasks.

3. Add a New User in Debian

To create a new sudo user in Debian, you need to have either an existing sudo user or root access to the system. This requirement ensures that only authorized users can grant sudo privileges to others.

In order to add a new user, follow these steps:

Log in to your Debian system using an existing sudo user account or as the root user. Open a terminal or connect to your Debian system via SSH.

If you have an existing sudo user:

Run the following command to create a new user:

$ sudo adduser senthil

Replace "senthil" with the desired username for the new sudo user.

Enter a strong password for the new user when prompted.

Provide any additional information requested during the user creation process.

If you have root access:

If the currently logged-in user does not have sudo rights, you will need to switch to the root account in order to create new sudo users.

Use any one of the following commands to switch to root user.

$ su -l 

Or

$ su -

By using su -l or su -, the root shell is initialized with an environment similar to a normal 'login' shell. This means that the root user's $PATH variable is correctly initialized, ensuring that system directories such as /sbin are included.

Next, run the following command to create a new user:

# adduser senthil

Again, replace "senthil" with your own username.

You will be prompted to set a password for the new user. Enter a strong password and confirm it.

Additional information about the new user, such as their full name, phone number, etc., may be requested. You can enter the information or leave it blank by pressing Enter.

Adding user `senthil' ...
Adding new group `senthil' (1001) ...
Adding new user `senthil' (1001) with group `senthil (1001)' ...
Creating home directory `/home/senthil' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for senthil
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y
Adding new user `senthil' to supplemental / extra groups `users' ...
Adding user `senthil' to group `users' ...

Debian 12의 사용자에게 추가, 삭제 및 권한을 부여하는 방법

3.1. Check Sudo Privileges for a Specific User

After creating a new user named "senthil", it's important to note that this user does not have sudo access by default. Without sudo privileges, the user won't be able to perform administrative tasks.

To verify whether a user has sudo access or not, you can use the following command:

# sudo -l -U senthil

Replace "senthil" with the actual username you want to check.

Sample output:

User senthil is not allowed to run sudo on debian12.

Debian 12의 사용자에게 추가, 삭제 및 권한을 부여하는 방법

As you can see, the user "senthil" has not been granted sudo privileges yet. If the user "senthil" has sudo access, the output will show the allowed commands and their associated restrictions, if any.

In the next steps, we will cover how to grant sudo privileges to the user "senthil" so they can perform administrative tasks.

4. Grant Sudo Privileges to Users in Debian

Add the newly created user to sudo group using the following command:

If you have an existing sudo user:

$ sudo adduser senthil sudo

If you have root access:

# adduser senthil sudo

Sample output:

Adding user `senthil' to group `sudo' ...
Done.

Debian 12의 사용자에게 추가, 삭제 및 권한을 부여하는 방법

We granted sudo permission to the user "senthil".

You can also the following command to add a user to sudo group.

# sudo usermod -aG sudo senthil

Now verify if the user is added in the sudo group, using command

# sudo -l -U senthil

Sample output:

Matching Defaults entries for senthil on debian12:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
    use_pty

User senthil may run the following commands on debian12:
    <strong><mark>(ALL : ALL) ALL</mark></strong>

Debian 12의 사용자에게 추가, 삭제 및 권한을 부여하는 방법

Here, the line (ALL : ALL) ALL in the above output indicates that the user "senthil" can run any command (ALL) as any user (ALL) with all available privileges.

The output confirms that the user "senthil" has been granted unrestricted sudo privileges on the Debian 12 system, allowing him to run any command as any user with full administrative capabilities.

If you view the contents of the sudoers file;

$ sudo cat /etc/sudoers

You would see some lines like below.

# User privilege specification
root	ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
<strong><mark>%sudo	ALL=(ALL:ALL) ALL</mark></strong>

# See sudoers(5) for more information on "@include" directives:

@includedir /etc/sudoers.d

The directive %sudo ALL=(ALL:ALL) ALL in the /etc/sudoers file is a rule that specifies the sudo privileges for members of the "sudo" group. Let's break down what each part of the directive means:

  • %sudo: This signifies that the rule applies to all users who are members of the "sudo" group. The % character denotes a group name.
  • ALL=(ALL:ALL): This portion defines the scope of the sudo rule. It indicates that the rule applies to any host (ALL) and allows users in the "sudo" group to run commands as any user and any group.
    • The first "ALL" represents the hosts or machines on which the sudo rule is applicable. In this case, "ALL" means the rule applies to any host. It allows members of the "sudo" group to execute commands with sudo privileges from any machine.
    • The second "ALL" represents the users or accounts as whom the commands can be executed. "ALL" means the members of the "sudo" group can run commands as any user on the system.
    • The third "ALL" represents the groups that the sudo commands can be executed as. Again, "ALL" means that the members of the "sudo" group can execute commands as any group on the system.
  • ALL: This specifies that the members of the "sudo" group can run any command.

In summary, the directive %sudo ALL=(ALL:ALL) ALL allows any user who is a member of the "sudo" group to execute any command with full administrative privileges. It grants broad sudo access to the users in the "sudo" group, enabling them to perform a wide range of administrative tasks on the system.

Since the user "senthil" is a member of "sudo" group, he can now run any command on any host. To put this in other word, he is one of the administrator.

5. Verify Sudo Privilege of Users

To verify if a user has the ability to perform administrative tasks with sudo, Log out from the current user session. On the login screen, select the new user you created. Enter the password for the new user and log in.

    Alternatively, you can quickly switch to the new user using the following command:

    # sudo -i -u senthil

    This command will instantly switch you to the specified user, in this case, "senthil".

    Once you are switched to the user, run any commands with the sudo prefix to perform administrative tasks. For example:

    $ sudo apt update

    Debian 12의 사용자에게 추가, 삭제 및 권한을 부여하는 방법

    As you witnessed in the above output, the user "senthil" has the ability to run administrative tasks with sudo privilege.

    6. Remove Sudo Access from Users

    Removing sudo access from a user in Debian systems is a delicate process that requires caution. It's important to ensure that you do not remove the real administrator from the "sudo" group, as there should always be at least one sudo user in the system.

    To revoke sudo permissions from a user, follow these steps:

    Make sure you are logged out from the user's session ("senthil") and logged in as another user with sudo privileges.

    To remove the user "senthil" from the "sudo" group, use the following command:

    $ sudo deluser senthil sudo

    This command will revoke the user's sudo permissions by removing them from the "sudo" group. Note that this action does not permanently delete the user from the system.

    Sample output:

    Removing user `senthil' from group `sudo' ...
    Done.

    Alternatively, you can use the following command to revoke sudo permissions:

    $ sudo gpasswd -d senthil sudo

    Running this command will have the same effect of removing the user "senthil" from the "sudo" group.

    After executing either of these commands, the user "senthil" will no longer have sudo access and will be considered a regular user without administrative privileges.

    To verify if the user has indeed been removed from the "sudo" group, you can run the following command:

    $ sudo -l -U senthil

    This command will display the user's sudo privileges. If the user is no longer listed as having sudo access, it confirms that the sudo permissions have been successfully revoked.

    User senthil is not allowed to run sudo on debian12.

    Debian 12의 사용자에게 추가, 삭제 및 권한을 부여하는 방법

    The user "senthil" is now removed from sudoer list.

    7. Remove Users Permanently

    Please exercise caution when permanently deleting users from the system, as this action is not reversible. Double-check that you are removing the correct user, and ensure that you have taken appropriate backups or precautions to prevent any unintended data loss.

    To permanently delete users from a Linux system, including their home directory and mail spool, follow these steps:

    Ensure that you are logged in as the root user or a user with sudo privileges.

    To delete a user, use the following command:

    $ sudo deluser senthil

    Replace "senthil" with the actual username of the user you want to remove.

    This command will remove the specified user from the system, including their user account details. However, their home directory and mail spool will remain intact.

    If you want to remove the user's home directory and mail spool along with their account, use the --remove-home option:

    $ sudo deluser --remove-home senthil

    This command ensures that not only the user account but also their home directory and mail spool are deleted.

    Conclusion

    Managing user privileges and granting sudo access in Debian systems is an essential aspect of maintaining system security and controlling administrative tasks. By following the step-by-step instructions provided, even beginners can successfully add, grant sudo access, and manage users in Debian systems.

    Remember to exercise caution when using sudo, grant privileges only to trusted users, and regularly review sudo logs to monitor user activity and identify any potential security issues.

    Related Read:

    • Add, Delete And Grant Sudo Privileges To Users In Alpine Linux
    • Add, Delete And Grant Sudo Privileges To Users In Arch Linux
    • Add, Delete And Grant Sudo Privileges To Users In CentOS
    • Add, Delete And Grant Sudo Privileges To Users In Fedora
    • Add, Delete And Grant Sudo Privileges To Users In Ubuntu
    • How To Allow Or Deny Sudo Access To A Group In Linux

    위 내용은 Debian 12의 사용자에게 추가, 삭제 및 권한을 부여하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

    성명
    본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
    Linux와 Windows 간의 가상화 지원의 차이점은 무엇입니까?Linux와 Windows 간의 가상화 지원의 차이점은 무엇입니까?Apr 22, 2025 pm 06:09 PM

    가상화 지원에서 Linux와 Windows의 주요 차이점은 다음과 같습니다. 1) Linux는 KVM과 Xen을 제공하며, 높은 커스터마이징 환경에 적합한 뛰어난 성능과 유연성을 제공합니다. 2) Windows는 친숙한 인터페이스를 통해 Hyper-V를 통한 가상화를 지원하며 Microsoft 소프트웨어에 의존하는 기업에 적합한 Microsoft Ecosystem과 밀접하게 통합됩니다.

    Linux 시스템 관리자의 주요 작업은 무엇입니까?Linux 시스템 관리자의 주요 작업은 무엇입니까?Apr 19, 2025 am 12:23 AM

    Linux 시스템 관리자의 주요 작업에는 시스템 모니터링 및 성능 조정, 사용자 관리, 소프트웨어 패키지 관리, 보안 관리 및 백업, 문제 해결 및 해상도, 성능 최적화 및 모범 사례가 포함됩니다. 1. 상단, HTOP 및 기타 도구를 사용하여 시스템 성능을 모니터링하고 조정하십시오. 2. 사용자 ADD 명령 및 기타 명령을 통해 사용자 계정 및 권한을 관리합니다. 3. APT 및 YUM을 사용하여 소프트웨어 패키지를 관리하여 시스템 업데이트 및 보안을 보장합니다. 4. 방화벽을 구성하고 로그를 모니터링하고 데이터 백업을 수행하여 시스템 보안을 보장합니다. 5. 로그 분석 및 공구 사용을 통해 문제를 해결하고 해결합니다. 6. 커널 매개 변수 및 응용 프로그램 구성을 최적화하고 모범 사례를 따라 시스템 성능 및 안정성을 향상시킵니다.

    Linux를 배우기가 어렵습니까?Linux를 배우기가 어렵습니까?Apr 18, 2025 am 12:23 AM

    Linux를 배우는 것은 어렵지 않습니다. 1.Linux는 UNIX를 기반으로 한 오픈 소스 운영 체제이며 서버, 임베디드 시스템 및 개인용 컴퓨터에서 널리 사용됩니다. 2. 파일 시스템 및 권한 관리 이해가 핵심입니다. 파일 시스템은 계층 적이며 권한에는 읽기, 쓰기 및 실행이 포함됩니다. 3. APT 및 DNF와 같은 패키지 관리 시스템은 소프트웨어 관리를 편리하게 만듭니다. 4. 프로세스 관리는 PS 및 최고 명령을 통해 구현됩니다. 5. MKDIR, CD, Touch 및 Nano와 같은 기본 명령에서 학습을 시작한 다음 쉘 스크립트 및 텍스트 처리와 같은 고급 사용법을 사용해보십시오. 6. 권한 문제와 같은 일반적인 오류는 Sudo 및 CHMod를 통해 해결할 수 있습니다. 7. 성능 최적화 제안에는 HTOP을 사용하여 리소스 모니터링, 불필요한 파일 청소 및 SY 사용이 포함됩니다.

    Linux 관리자의 급여는 무엇입니까?Linux 관리자의 급여는 무엇입니까?Apr 17, 2025 am 12:24 AM

    Linux 관리자의 평균 연봉은 미국에서 $ 75,000 ~ $ 95,000, 유럽에서는 40,000 유로에서 60,000 유로입니다. 급여를 늘리려면 다음과 같이 할 수 있습니다. 1. 클라우드 컴퓨팅 및 컨테이너 기술과 같은 새로운 기술을 지속적으로 배울 수 있습니다. 2. 프로젝트 경험을 축적하고 포트폴리오를 설정합니다. 3. 전문 네트워크를 설정하고 네트워크를 확장하십시오.

    Linux의 주요 목적은 무엇입니까?Linux의 주요 목적은 무엇입니까?Apr 16, 2025 am 12:19 AM

    Linux의 주요 용도에는 다음이 포함됩니다. 1. 서버 운영 체제, 2. 임베디드 시스템, 3. 데스크탑 운영 체제, 4. 개발 및 테스트 환경. Linux는이 분야에서 뛰어나 안정성, 보안 및 효율적인 개발 도구를 제공합니다.

    인터넷은 Linux에서 실행됩니까?인터넷은 Linux에서 실행됩니까?Apr 14, 2025 am 12:03 AM

    인터넷은 단일 운영 체제에 의존하지 않지만 Linux는 이에 중요한 역할을합니다. Linux는 서버 및 네트워크 장치에서 널리 사용되며 안정성, 보안 및 확장 성으로 인기가 있습니다.

    Linux 운영이란 무엇입니까?Linux 운영이란 무엇입니까?Apr 13, 2025 am 12:20 AM

    Linux 운영 체제의 핵심은 명령 줄 인터페이스이며 명령 줄을 통해 다양한 작업을 수행 할 수 있습니다. 1. 파일 및 디렉토리 작업 LS, CD, MKDIR, RM 및 기타 명령을 사용하여 파일 및 디렉토리를 관리합니다. 2. 사용자 및 권한 관리는 UserAdd, Passwd, CHMOD 및 기타 명령을 통해 시스템 보안 및 리소스 할당을 보장합니다. 3. 프로세스 관리는 PS, Kill 및 기타 명령을 사용하여 시스템 프로세스를 모니터링하고 제어합니다. 4. 네트워크 운영에는 Ping, Ifconfig, SSH 및 기타 명령이 포함되어 있으며 네트워크 연결을 구성하고 관리합니다. 5. 시스템 모니터링 및 유지 관리 Top, DF, Du와 같은 명령을 사용하여 시스템의 작동 상태 및 리소스 사용을 이해합니다.

    Linux 별칭을 사용하여 사용자 정의 명령 바로 가기로 생산성을 높이십시오Linux 별칭을 사용하여 사용자 정의 명령 바로 가기로 생산성을 높이십시오Apr 12, 2025 am 11:43 AM

    소개 Linux는 유연성과 효율성으로 인해 개발자, 시스템 관리자 및 전원 사용자가 선호하는 강력한 운영 체제입니다. 그러나 길고 복잡한 명령을 자주 사용하는 것은 지루하고 응급실이 될 수 있습니다.

    See all articles

    핫 AI 도구

    Undresser.AI Undress

    Undresser.AI Undress

    사실적인 누드 사진을 만들기 위한 AI 기반 앱

    AI Clothes Remover

    AI Clothes Remover

    사진에서 옷을 제거하는 온라인 AI 도구입니다.

    Undress AI Tool

    Undress AI Tool

    무료로 이미지를 벗다

    Clothoff.io

    Clothoff.io

    AI 옷 제거제

    Video Face Swap

    Video Face Swap

    완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

    뜨거운 도구

    VSCode Windows 64비트 다운로드

    VSCode Windows 64비트 다운로드

    Microsoft에서 출시한 강력한 무료 IDE 편집기

    DVWA

    DVWA

    DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

    PhpStorm 맥 버전

    PhpStorm 맥 버전

    최신(2018.2.1) 전문 PHP 통합 개발 도구

    SublimeText3 영어 버전

    SublimeText3 영어 버전

    권장 사항: Win 버전, 코드 프롬프트 지원!

    Atom Editor Mac 버전 다운로드

    Atom Editor Mac 버전 다운로드

    가장 인기 있는 오픈 소스 편집기