Managing Users and Hostname on Ubuntu Server

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!

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值