侧边栏壁纸
  • 累计撰写 99 篇文章
  • 累计创建 54 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

debian set user as root user and disable default root

FlyingEagle
2024-06-11 / 0 评论 / 0 点赞 / 28 阅读 / 4,699 字

User
how to add user in debian and set the new user as a administrator?
ChatGPT
To add a new user and set them as an administrator on a Debian system, you can follow these steps:

Step 1: Add a New User

  1. Open a terminal.

  2. Use the adduser command to add a new user. Replace username with the desired username.

    sudo adduser username
    

    This command will prompt you to set a password and enter some optional information (like full name, room number, etc.).

Step 2: Add the User to the sudo Group

To grant the new user administrative privileges, add them to the sudo group.

  1. Use the usermod command:

    sudo usermod -aG sudo username
    

    The -aG options mean “append the user to the specified group(s).”

Step 3: Verify the User’s Group Membership

To ensure that the user has been added to the sudo group, you can use the groups command:

  1. Log in as the new user:

    su - username
    
  2. Check the groups the user belongs to:

    groups
    

    You should see sudo listed among the groups.

Step 4: Test the New User’s Sudo Privileges

To confirm that the new user has administrative privileges, you can test running a command with sudo:

  1. Still logged in as the new user, try running a command that requires sudo, such as updating the package list:

    sudo apt update
    

    If the user is prompted for their password and the command executes successfully, the setup is correct.

Full Example

Here’s the full sequence of commands you might use, replacing username with the desired username:

sudo adduser username
sudo usermod -aG sudo username
su - username
groups
sudo apt update

This sequence will create a new user, add them to the sudo group, and verify that they have the necessary administrative privileges.
User
after I promt the command sudo apt update
it shows bash: sudo: command not found
ChatGPT
The error bash: sudo: command not found indicates that the sudo command is not available. This can happen if sudo is not installed or if the environment path is not set up correctly.

To resolve this issue, you can try the following steps:

Step 1: Ensure sudo is Installed

  1. Switch to the root user:

    su -
    
  2. Check if sudo is installed:

    apt list --installed | grep sudo
    

    If sudo is not installed, install it using:

    apt update
    apt install sudo
    

Step 2: Ensure the User’s Path Includes /usr/bin

Sometimes the user’s PATH environment variable might not include /usr/bin, where sudo is typically located.

  1. Check the PATH:

    echo $PATH
    

    Ensure /usr/bin is part of the PATH. If not, you can add it by editing the user’s profile file (e.g., ~/.bashrc or ~/.profile).

  2. Edit the profile file (assuming ~/.bashrc):

    nano ~/.bashrc
    
  3. Add the following line if it’s not already present:

    export PATH=$PATH:/usr/bin
    
  4. Reload the profile file:

    source ~/.bashrc
    

Step 3: Test the sudo Command

  1. Log out from the root user and switch back to the new user:

    exit
    
  2. Try running the sudo command again:

    sudo apt update
    

Full Example

Here is a sequence of commands to follow if you encounter the sudo: command not found error:

  1. Switch to the root user:

    su -
    
  2. Install sudo if it is not already installed:

    apt update
    apt install sudo
    
  3. Switch to the new user:

    su - username
    
  4. Check and set the PATH:

    echo $PATH
    

    If /usr/bin is not in the PATH:

    echo 'export PATH=$PATH:/usr/bin' >> ~/.bashrc
    source ~/.bashrc
    
  5. Test the sudo command:

    sudo apt update
    

This should resolve the issue and allow the new user to use the sudo command.
User
how to disable root account?
ChatGPT
Disabling the root account in Debian can be done by setting the root password to an invalid value, which effectively prevents direct login as root. Here are the steps to disable the root account:

Step 1: Ensure You Have a Sudo User

Before disabling the root account, make sure you have a user with sudo privileges, as you’ll need to perform administrative tasks using sudo instead of logging in as root directly.

Step 2: Disable the Root Account

  1. Open a terminal and switch to your sudo user if you are not already logged in as one:

    su - username
    
  2. Disable the root account by setting its password to an invalid value. This can be done using the passwd command:

    sudo passwd -l root
    

    The -l option locks the password, effectively disabling the account.

Step 3: Verify the Root Account is Disabled

  1. Attempt to switch to the root user:

    su -
    

    You should see an error message indicating that the account is disabled.

Step 4: Ensure System Security

To ensure that the system remains secure after disabling the root account, verify that the new sudo user can perform administrative tasks without issues.

  1. Try updating the package list using sudo:

    sudo apt update
    

    If the command executes successfully, your sudo user is properly configured.

Additional Security Measures

While disabling the root account, you might also consider the following security measures:

  • Use SSH Keys for Remote Access: Configure SSH keys for the sudo user and disable password-based authentication in the SSH configuration (/etc/ssh/sshd_config).
  • Configure the Firewall: Use ufw (Uncomplicated Firewall) or another firewall tool to restrict access to your system.
  • Regular Updates: Keep your system and packages up to date to ensure you have the latest security patches.

Example of Full Process

Here’s the full process for disabling the root account and ensuring you have a properly configured sudo user:

  1. Log in as your sudo user:

    su - username
    
  2. Lock the root account:

    sudo passwd -l root
    
  3. Verify the root account is disabled:

    su -
    

    You should see an error message indicating that the root account is locked.

  4. Ensure the sudo user can perform administrative tasks:

    sudo apt update
    

By following these steps, you’ll disable the root account and ensure that you can still perform necessary administrative tasks using a user with sudo privileges.

0

评论区