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!

相关推荐
DeskUI~~12 小时前
8.4M,我把 Linux 变成了一块“磁盘”
linux·运维·服务器
少陽君13 小时前
如何在 PVE 中下载并导入 Ubuntu 24.04 Server 云镜像
linux·数据库·ubuntu
无足鸟ICT13 小时前
【RHCA+】_proc_pid_environ
linux·运维·服务器
wacsii14 小时前
【Linux操作系统】从零手写 mystdio:静态库、动态库制作与第三方链接踩坑
linux·服务器
嵌入式 Linux手记15 小时前
静态库动态库到底差在哪
linux·c语言·嵌入式
71777715 小时前
2026 中国企业 DevOps 平台怎么选:从排名诉求回到可核验的选型维度
运维·devops
信安IT租赁16 小时前
小公司服务器的自启动脚本:用 systemd 做成服务,开机自动跑
linux·运维·服务器
陈秋月16 小时前
从一句注释到 root:GoldenEye 靶机通关记录
linux
东鹏特饮16 小时前
Docker 容器技术详细指南
运维·docker·容器
用户960984579224016 小时前
Ubuntu 开发软件全链路美化:VS Code/Cursor/tmux/delta/fzf 实战
linux