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!

相关推荐
保卫大狮兄11 分钟前
设备利用率低,到底是设备问题还是排产问题?
大数据·运维·服务器
jzwalliser30 分钟前
Ubuntu的美化:深度定制指南
ubuntu·gnome·美化
独行侠影a36 分钟前
6G研发加速:太赫兹通信与智能超表面如何重塑未来网络?
运维·服务器
便利店10241 小时前
企业远程办公如何打通内网?网络层隧道与封装直觉
运维·服务器·网络·vpn·隧道
yunwei372 小时前
eBPF 教程:精准隔离已建立的 TCP 连接
linux·安全·开源
weixin_445476683 小时前
linux下lims部署详细步骤参考
linux
戴西软件3 小时前
戴西CAxWorks.VPG车辆工程仿真软件技术解析(上)——安全仿真体系的自动化构建
运维·网络·数据库·人工智能·算法·安全·自动化
数据百晓通4 小时前
2026 智能体重构数据治理:全链路 AI、云生态、场景嵌入赛道解析
大数据·运维·人工智能
LuDvei4 小时前
怎么把数据上传到云端
运维·服务器
奇特認4 小时前
数据库MySQL 1.安装环境部署
linux·运维·服务器