Managing Users and Hostname on Ubuntu Server

avatar
作者
猴君
阅读量:0

Tutorial: Managing Users and Hostname on Ubuntu

1. Change Hostname

To change the hostname of your system:

  1. Edit the hostname file:

    sudo nano /etc/hostname 

    Replace the existing name with your new hostname.

  2. Edit the hosts file:

    sudo nano /etc/hosts 

    Update the line that starts with 127.0.1.1 to reflect the new hostname.

  3. Apply the changes:

    sudo systemctl restart systemd-logind.service 
2. Rename a User

To rename a user:

  1. Rename the user:

    sudo usermod -l new_username old_username 
  2. Rename the home directory (if needed):

    sudo usermod -d /homes/new_username -m new_username 
3. Give Sudo Privileges to a User

To add a user to the sudo group:

sudo usermod -aG sudo username 
4. Add a New User

To add a new user with a home directory in /homes:

  1. Create the directory (if it doesn’t exist):

    sudo mkdir -p /homes 
  2. Add the user:

    sudo useradd -m -d /homes/new_user -s /bin/bash new_user 
  3. Set a password:

    sudo passwd new_user 
5. Set Permissions for Home Directories

Ensure home directories are secure:

  1. Set permissions:

    sudo chmod 700 /homes/new_user 
  2. Set ownership:

    sudo chown new_user:new_user /homes/new_user 

Summary

  • Change hostname by editing /etc/hostname and /etc/hosts.
  • Rename users with usermod.
  • Grant sudo access by adding the user to the sudo group.
  • Add new users with custom home directories in /homes.
  • Set appropriate permissions for security.

If you have any more questions or need further assistance, feel free to ask!

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!