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:

    bash 复制代码
    sudo nano /etc/hostname

    Replace the existing name with your new hostname.

  2. Edit the hosts file:

    bash 复制代码
    sudo nano /etc/hosts

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

  3. Apply the changes:

    bash 复制代码
    sudo systemctl restart systemd-logind.service
2. Rename a User

To rename a user:

  1. Rename the user:

    bash 复制代码
    sudo usermod -l new_username old_username
  2. Rename the home directory (if needed):

    bash 复制代码
    sudo usermod -d /homes/new_username -m new_username
3. Give Sudo Privileges to a User

To add a user to the sudo group:

bash 复制代码
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):

    bash 复制代码
    sudo mkdir -p /homes
  2. Add the user:

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

    bash 复制代码
    sudo passwd new_user
5. Set Permissions for Home Directories

Ensure home directories are secure:

  1. Set permissions:

    bash 复制代码
    sudo chmod 700 /homes/new_user
  2. Set ownership:

    bash 复制代码
    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!

相关推荐
AI智图坊1 分钟前
电商详情页转化率提升实战:基于AI的“卖点-视觉”转化链路设计与自动化实现
大数据·运维·人工智能·gpt·ai作画·自动化·aigc
呉師傅7 分钟前
联想M7400Pro提示无法打印0B 关闭电源然后重新打开故障维修分享
运维·网络·windows·电脑
2023自学中16 分钟前
Linux虚拟机,VSCode + GDB 调试配置:launch.json 模板
linux·vscode·嵌入式
meilindehuzi_a18 分钟前
从零搭建本地 Mock 服务器与异步控制流(async/await)深度架构实践
运维·服务器·架构
艾莉丝努力练剑18 分钟前
【QT】窗口
运维·网络·数据库·qt·计算机网络·microsoft
RisunJan19 分钟前
Linux命令-ntsysv(集中管理系统的各种服务)
linux·运维·服务器
Championship.23.2421 分钟前
Linux 3.0 USB机制深度解析:USB 3.0支持与传统外设驱动架构
linux·运维·架构·usb
yyuuuzz22 分钟前
aws亚马逊云服务的基础认知与常见场景
大数据·运维·服务器·网络·云计算·aws
鼎讯信通23 分钟前
DLG-1 高压测试设备,补齐能源电缆运维检测短板
运维·能源
剑神一笑24 分钟前
Linux lsblk 命令详解:块设备信息查看与磁盘管理实战
linux·运维·服务器