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!

相关推荐
信创DevOps先锋2 分钟前
Gitee:中国开发者生态的数字化转型基石与创新加速器
运维·gitee·devops
Crazy CodeCrafter19 分钟前
房租年年涨,客流年年少,服装店还要开吗?
大数据·运维·微信·自动化·开源软件
淼淼爱喝水23 分钟前
Ansible 配置与环境搭建超全教程(自动化运维基础)
运维·自动化·ansible
xlp666hub30 分钟前
深度剖析Linux Input子系统(2):驱动开发流程与现代 Multi-touch 协议
linux
yj_xqj1 小时前
HAproxy负载均衡集群部署
运维·负载均衡
路由侠内网穿透1 小时前
本地部署开源工作空间工具 AFFiNE 并实现外部访问
运维·服务器·数据库·物联网·开源
zzzsde1 小时前
【Linux】Ext文件系统(1)
linux·运维·服务器
爱学习的小囧1 小时前
ESXi 8.0 无法选择分区方式 小白级详细解决办法
运维·服务器·网络·虚拟化·esxi8.0
F1FJJ1 小时前
什么是 Shield CLI?视频讲解:一条命令,可浏览器远程访问一切内部服务(RDP/VNC/SSH/数据库等)
运维·网络·数据库·网络协议·ssh
WordPress学习笔记1 小时前
wordpress网站上传不了图片可能是文件夹的权限的原因
运维·wordpress·文件夹权限·uploads·wordpress上传错误