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!

相关推荐
萧行之21 分钟前
Ubuntu Node.js 版本管理工具 n 完整安装与使用教程
linux·前端
啦啦啦小石头25 分钟前
Docker+Nvidia Container Toolkit 在ubuntu下离线安装
ubuntu·docker·eureka
乐维_lwops26 分钟前
什么是可扩展、可接入的智能运维体?
运维·开放平台·运维智能体
Ares-Wang8 小时前
Linux》》systemd 、service、systemctl daemon-reload、systemctl restart docker
linux·运维·docker
tinygone9 小时前
OpenClaw之Memory配置成本地模式,Ubuntu+CUDA+cuDNN+llama.cpp
人工智能·ubuntu·llama
安审若无9 小时前
运维知识框架
运维·服务器
阿拉斯攀登10 小时前
从入门到实战:CMake 与 Android JNI/NDK 开发全解析
android·linux·c++·yolo·cmake
Arvin62712 小时前
Nginx 添加账号密码访问验证
运维·服务器·nginx
风曦Kisaki13 小时前
# Linux 磁盘查看命令详解:df 与 du
linux·运维·网络
路溪非溪13 小时前
Linux中gpio子系统的现代接口
linux·arm开发·驱动开发