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!

相关推荐
m0_6948455732 分钟前
服务器如何配置防火墙规则开放/关闭端口?
linux·服务器·安全·云计算
降世神童42 分钟前
华为云Flexus+DeepSeek征文| 使用华为云CCE容器部署Dify-LLM高可用方案的验证与测试
运维·华为云·aigc
降世神童42 分钟前
华为云Flexus+DeepSeek征文| 基于华为云Dify-LLM高可用平台开发运维故障处理智能体
运维·华为云·aigc
阿巴~阿巴~1 小时前
Linux基本命令篇 —— alias命令
linux·服务器·bash
好名字更能让你们记住我2 小时前
Linux多线程(十二)之【生产者消费者模型】
linux·运维·服务器·jvm·windows·centos
门思科技2 小时前
设计可靠 LoRaWAN 设备时需要考虑的关键能力
运维·服务器·网络·嵌入式硬件·物联网
矩阵老炮2 小时前
Ubuntu20.4编译AOSP源码实践
ubuntu·aosp
学习编程的gas2 小时前
Linux开发工具——gcc/g++
linux·运维·服务器
嵌入式成长家2 小时前
ubuntu rules 使用规则
linux·ubuntu·rules 使用规则
_可乐无糖3 小时前
AWS WebRTC: 判断viewer端拉流是否稳定的算法
linux·服务器·webrtc·aws