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!

相关推荐
日取其半万世不竭几秒前
新服务器买完 24 小时内要做什么?安全加固清单
运维·服务器·安全
code monkey.2 分钟前
【Linux之旅】HTTP 协议解析:从请求格式到构建 Web 服务器
linux·服务器·网络·http
tiannian12207 分钟前
资产管理从手工到智能:三种技术路径的优劣与适用场景
运维·rfid·资产管理系统
l齐天11 分钟前
Ubuntu 中编译 Go + PBC 程序为 Windows 11 可运行文件
windows·ubuntu·golang
_codemonster11 分钟前
传统模式 vs DevOps 模式
运维·devops
vortex519 分钟前
Linux 传统设计哲学:通过调用名区分行为的艺术
linux·运维·网络
Gong-Yu30 分钟前
MySQL数据库运维——性能优化进阶2️⃣
运维·数据库·mysql·性能优化
深圳恒讯30 分钟前
非洲服务器延迟高吗?实测数据与场景化解读
运维·服务器·前端
志栋智能30 分钟前
超自动化安全的实施路径:从单点场景到体系化建设
运维·网络·安全·自动化
嵌入式-老费31 分钟前
esp32开发与应用(esp32-s3的usb转串口功能)
linux·运维·服务器