목차
Introduction
1. Restrict Su Command Usage to Particular Users in Debian and its Derivatives
1.1. Revert su Command to its Original Configuration
2. Limit the Use of Su Command in RHEL-based Systems
Frequently Asked Questions
Conclusion
시스템 튜토리얼 리눅스 Linux에서 SU 명령을 공인 사용자로 제한하는 방법

Linux에서 SU 명령을 공인 사용자로 제한하는 방법

Mar 23, 2025 am 10:13 AM

The su command is a powerful tool that can be used to switch to another user's account. However, it can also be used by bad persons to gain unauthorized access to your system. By restricting the use of the su command, you can help to protect your Linux system from unauthorized access.

Table of Contents

Introduction

In our previous tutorial, we learned how to "grant or deny sudo access to a group" in Linux to make things safer and manage groups better. However, this alone may not be enough.

If a bad person gains access to an account without sudo privileges, they can still try to login as root or another user with sudo privileges by using the su command. As you already know, the su command allows users to execute commands as other accounts, including the root account.

To address this concern, we need to ensure that only specific accounts have the privilege to use the su command. This extra step will add even more security to our system. In this brief tutorial, we will learn how to restrict the su command usage to authorized users in Linux.

Here are some of the reasons why you might want to restrict the use of the su command:

  • To prevent unauthorized users from gaining access to sensitive data.
  • To prevent unauthorized users from making changes to system settings.
  • To prevent unauthorized users from installing malicious software.

1. Restrict Su Command Usage to Particular Users in Debian and its Derivatives

To limit who can use su command, we need to create a dedicated group and allow only the members of that particular group can use su command. Let us see how to do that.

1. For the purpose of this guide, I am going to create two users namely user1 and user2.

$ sudo adduser user1
로그인 후 복사
로그인 후 복사
$ sudo adduser user2
로그인 후 복사

2. Next, create a new group called adminmembers.

$ sudo groupadd adminmembers
로그인 후 복사

3. Add the 'user1' and 'user2' to the group.

$ sudo usermod -aG adminmembers user1
로그인 후 복사
$ sudo usermod -aG adminmembers user2
로그인 후 복사

Similarly, add all other users to this group.

You can verify the members of this group using command:

$ getent group adminmembers
로그인 후 복사

Sample output:

adminmembers:x:1005:user1,user2
로그인 후 복사

4. Now, run the following command to restrict the su command to only the members of the 'adminmembers' group:

$ sudo dpkg-statoverride --update --add root adminmembers 4750 /bin/su
로그인 후 복사

Here, the sudo dpkg-statoverride --update --add command is used to override file permissions and ownership for a specific file on a Debian-based Linux distribution. In this case, the command is setting a special permission and ownership for the /bin/su binary.

Let's break down the command:

  • sudo: This is used to run the command with superuser (root) privileges. You will need administrative privileges to modify system files.
  • dpkg-statoverride: This is a command-line tool in Debian-based systems that allows you to override file permissions and ownership of packages managed by the package manager.
  • --update: This option tells dpkg-statoverride to update the specified override if it already exists.
  • --add: This option indicates that we want to add a new override.
  • root: This specifies the user whose ownership will be set for the file.
  • adminmembers: This specifies the group whose ownership will be set for the file.
  • 4750: This is the numeric representation of the file permissions. The value 4750 is a special permission called "SetUID" (Set User ID) on execution. When the su binary has the SetUID bit set, it runs with the effective user ID of the file owner (root) instead of the user who executed it. This allows regular users to switch to the root user's privileges temporarily when running su.
  • /bin/su: This is the path to the file for which the override is being set. In this case, it's the /bin/su binary, which allows users to switch to another user's account (often the root user) after providing the necessary password.

So, the command is adding an override for the permissions and ownership of the /bin/su binary. It sets the file's owner to root, group to adminmembers, and gives the SetUID permission to the file. This means that when users run the su command, it will run with root privileges, allowing them to switch to the root user or another user with superuser privileges after providing the appropriate password. The non-members of the 'adminmembers' group can't use su command, even if they have sudo privilege.

Let us verify it. Right now, I'm logged into my system as a user named 'ostechnix', and this user has sudo privileges.

$ sudo -lU ostechnix
[sudo] password for ostechnix: 
Matching Defaults entries for ostechnix on debian12:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
    use_pty

User ostechnix may run the following commands on debian12:
    <strong><mark>(ALL : ALL) ALL</mark></strong>
로그인 후 복사

As you see in the above output, the user 'ostechnix' can able to run all commands.

Now, let use su command and see what happens.

$ su - user1
로그인 후 복사

Sample output:

-bash: /usr/bin/su: Permission denied
로그인 후 복사

See? The user 'ostechnix' can't use the su command despite having sudo privilege because he is not a member of the 'adminmembers' group. Because, we limited the su command usage to only the members of that specific group.

Linux에서 SU 명령을 공인 사용자로 제한하는 방법

Now log out from the current session and log back in as 'user1' or 'user2' or any member of the 'adminmembers' group.

And, check if su command works:

user1@debian12:~$ whoami
user1
user1@debian12:~$ 
user1@debian12:~$ su - user2
Password: 
user2@debian12:~$ 
user2@debian12:~$ whoami
user2
user2@debian12:~$ 
user2@debian12:~$ su - user1
Password: 
user1@debian12:~$ 
user1@debian12:~$ whoami
user1
user1@debian12:~$ 
로그인 후 복사

Linux에서 SU 명령을 공인 사용자로 제한하는 방법

As you can observe in the above output, both 'user1' and 'user2' have the ability to switch between different user accounts using the su command because they are both members of the 'adminmembers' group.

1.1. Revert su Command to its Original Configuration

To undo the changes made by the command sudo dpkg-statoverride --update --add root adminmembers 4750 /bin/su, you need to remove the override that was set for the /bin/su binary. The dpkg-statoverride command allows you to manage file permissions and ownership for packages in Debian-based systems.

To remove the override for the /bin/su binary, follow these steps:

1. Check the current dpkg-statoverride configuration:

Before removing the override, it's a good idea to check if the override for /bin/su exists and what the current configuration is. Run the following command to view the current dpkg-statoverride settings:

$ dpkg-statoverride --list /bin/su
로그인 후 복사

This command will show you the current permissions and ownership set for the /bin/su binary.

Sample output:

root adminmembers 4750 /bin/su
로그인 후 복사

2. Remove the dpkg-statoverride entry:

To remove the override, use the following command:

$ sudo dpkg-statoverride --remove /bin/su
로그인 후 복사

This command will remove the override entry for /bin/su.

3. Reset the original permissions (if needed):

If you want to reset the permissions of /bin/su to the default value, use the following command:

$ sudo chmod 4755 /bin/su
로그인 후 복사

The 4755 value sets the SetUID bit on the file, which allows the su command to run with root privileges.

Linux에서 SU 명령을 공인 사용자로 제한하는 방법

With these steps, you should have undone the changes made by the initial sudo dpkg-statoverride --update --add root adminmembers 4750 /bin/su command and reverted the /bin/su binary to its original configuration.

Warning: Always exercise caution when modifying system configurations, especially when dealing with file permissions and ownership, as improper changes can impact system security and stability.

2. Limit the Use of Su Command in RHEL-based Systems

The previous method is only for Debian and its derivatives like Ubuntu. The process of limiting su command usage in RPM-based is different. Let us see how to do that.

To limit the use of the su command in RHEL-based systems, follow these steps:

1. Create a new user (e.g., "user1") and add him to the "wheel" group:

$ sudo adduser user1
로그인 후 복사
로그인 후 복사
$ sudo passwd user1
로그인 후 복사
$ sudo usermod -G wheel user1
로그인 후 복사

This grants the user "user1" access to the su command through the "wheel" group, which is often configured to have special privileges.

2. Open the PAM configuration file for su using a text editor:

$ sudo nano /etc/pam.d/su
로그인 후 복사

3. Append the following line at the end of the file or uncomment this line if it already exists:

auth required /lib/security/pam_wheel.so use_uid
로그인 후 복사

Alternatively, you can uncomment or append this line:

auth required pam_wheel.so use_uid
로그인 후 복사

4. Save the changes and close the file.

With these steps, the su command will be restricted, and only users belonging to the "wheel" group will be allowed to use it.

When you try to use su command from a non-member of wheel group, you would see an output like below:

[user3@Almalinux9ct ~]$ su - user1
Password: 
su: Module is unknown
로그인 후 복사

Linux에서 SU 명령을 공인 사용자로 제한하는 방법

To revert back to the original settings, simply comment or remove the line that you've added in the previous step.

Frequently Asked Questions

Q: What is the su command in Linux?

A: The su command, short for "switch user," allows users to execute commands as a different user, often the root user with superuser privileges.

Q: Why should I restrict the su command usage?

A: Restricting su command usage enhances security by limiting access to privileged operations, reducing the risk of unauthorized users gaining unrestricted control over the system.

Q: How can I limit the use of the su command?

A: You can limit su command usage by configuring the PAM (Pluggable Authentication Modules) file, allowing access only to specific groups or users, such as the "wheel" group.

Q: How do I grant access to su for a specific group?

A: Add the desired users to a designated group (e.g., "wheel") and configure the /etc/pam.d/su file to require this group membership for su command access.

Q: How can I check if the su command is appropriately restricted?

A: Use the su command with a non-privileged user to verify that access is limited only to authorized users or groups.

Conclusion

Restricting the usage of the su command in Linux is a vital step towards strengthening Linux system security and safeguarding sensitive information. By carefully controlling access to privileged commands, such as su, we can mitigate the risk of unauthorized users gaining elevated privileges and potentially compromising the system.

Implementing these restrictions, in conjunction with other security best practices, creates a more resilient and secure Linux environment.

Related Read:

  • How To Run Commands As Another User Via Sudo In Linux

위 내용은 Linux에서 SU 명령을 공인 사용자로 제한하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 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 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

가장 잘 사용되는 Linux는 무엇입니까? 가장 잘 사용되는 Linux는 무엇입니까? Apr 03, 2025 am 12:11 AM

Linux는 서버 관리, 임베디드 시스템 및 데스크탑 환경으로 사용되는 것이 가장 좋습니다. 1) 서버 관리에서 Linux는 웹 사이트, 데이터베이스 및 응용 프로그램을 호스팅하는 데 사용되어 안정성과 안정성을 제공합니다. 2) 임베디드 시스템에서 Linux는 유연성과 안정성으로 인해 스마트 홈 및 자동차 전자 시스템에서 널리 사용됩니다. 3) 데스크탑 환경에서 Linux는 풍부한 응용 프로그램과 효율적인 성능을 제공합니다.

Linux의 5 가지 기본 구성 요소는 무엇입니까? Linux의 5 가지 기본 구성 요소는 무엇입니까? Apr 06, 2025 am 12:05 AM

Linux의 5 가지 기본 구성 요소는 다음과 같습니다. 1. 커널, 하드웨어 리소스 관리; 2. 기능과 서비스를 제공하는 시스템 라이브러리; 3. 쉘, 사용자가 시스템과 상호 작용할 수있는 인터페이스; 4. 파일 시스템, 데이터 저장 및 구성; 5. 시스템 리소스를 사용하여 기능을 구현합니다.

기본 리눅스 관리 란 무엇입니까? 기본 리눅스 관리 란 무엇입니까? Apr 02, 2025 pm 02:09 PM

Linux 시스템 관리는 구성, 모니터링 및 유지 보수를 통해 시스템 안정성, 효율성 및 보안을 보장합니다. 1. TOP 및 SystemCTL과 같은 마스터 쉘 명령. 2. APT 또는 YUM을 사용하여 소프트웨어 패키지를 관리하십시오. 3. 효율성을 향상시키기 위해 자동 스크립트를 작성하십시오. 4. 권한 문제와 같은 일반적인 디버깅 오류. 5. 모니터링 도구를 통해 성능을 최적화하십시오.

Linux 기본 사항을 배우는 방법? Linux 기본 사항을 배우는 방법? Apr 10, 2025 am 09:32 AM

기본 Linux 학습 방법은 다음과 같습니다. 1. 파일 시스템 및 명령 줄 인터페이스 이해, 2. LS, CD, MKDIR, 3. 파일 생성 및 편집과 같은 파일 작업 배우기, 4. 파이프 라인 및 GREP 명령과 같은 고급 사용법, 5. 연습 및 탐색을 통해 지속적으로 기술을 향상시킵니다.

Linux를 가장 많이 사용하는 것은 무엇입니까? Linux를 가장 많이 사용하는 것은 무엇입니까? Apr 09, 2025 am 12:02 AM

Linux는 서버, 임베디드 시스템 및 데스크탑 환경에서 널리 사용됩니다. 1) 서버 필드에서 Linux는 안정성 및 보안으로 인해 웹 사이트, 데이터베이스 및 응용 프로그램을 호스팅하기에 이상적인 선택이되었습니다. 2) 임베디드 시스템에서 Linux는 높은 사용자 정의 및 효율성으로 인기가 있습니다. 3) 데스크탑 환경에서 Linux는 다양한 사용자의 요구를 충족시키기 위해 다양한 데스크탑 환경을 제공합니다.

Linux 장치 란 무엇입니까? Linux 장치 란 무엇입니까? Apr 05, 2025 am 12:04 AM

Linux 장치는 서버, 개인용 컴퓨터, 스마트 폰 및 임베디드 시스템을 포함한 Linux 운영 체제를 실행하는 하드웨어 장치입니다. 그들은 Linux의 힘을 활용하여 웹 사이트 호스팅 및 빅 데이터 분석과 같은 다양한 작업을 수행합니다.

리눅스의 단점은 무엇입니까? 리눅스의 단점은 무엇입니까? Apr 08, 2025 am 12:01 AM

Linux의 단점에는 사용자 경험, 소프트웨어 호환성, 하드웨어 지원 및 학습 곡선이 포함됩니다. 1. 사용자 경험은 Windows 또는 MacOS만큼 친절하지 않으며 명령 줄 인터페이스에 의존합니다. 2. 소프트웨어 호환성은 다른 시스템만큼 좋지 않으며 많은 상용 소프트웨어의 기본 버전이 부족합니다. 3. 하드웨어 지원은 Windows만큼 포괄적이지 않으며 드라이버를 수동으로 컴파일 할 수 있습니다. 4. 학습 곡선은 가파르고 명령 줄 운영을 마스터하는 데 시간과 인내가 필요합니다.

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

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

See all articles