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!

相关推荐
PH_modest28 分钟前
【Linux跬步积累】——thread封装
linux·运维·服务器
秋说32 分钟前
本地Ubuntu轻松部署高效性能监控平台SigNoz与远程使用教程
linux·运维·ubuntu
Joeysoda35 分钟前
Java数据结构 (从0构建链表(LinkedList))
java·linux·开发语言·数据结构·windows·链表·1024程序员节
一个处女座的暖男程序猿1 小时前
MyBatis Plus 中常用的 Service 功能
linux·windows·mybatis
晚秋贰拾伍1 小时前
设计模式的艺术-命令模式
运维·设计模式·运维开发·命令模式·开闭原则
happybasic1 小时前
一个基于Python+Appium的手机自动化项目~~
运维·appium·自动化
A charmer1 小时前
Linux 进程环境变量:深入理解与实践指南
linux·运维·服务器·开发
云游的二狗1 小时前
【VMWare Workstation 17】安装Debian 12.8DVD
运维·docker·debian
cv-daily2 小时前
通过docker overlay2目录名查找容器名和容器ID
运维·docker·容器
努力的小T3 小时前
基于 Bash 脚本的系统信息定时收集方案
linux·运维·服务器·网络·云计算·bash