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!

相关推荐
段ヤシ.1 小时前
银河麒麟(内核CentOS8)安装rbenv、ruby2.6.5和rails5.2.6
linux·centos·银河麒麟·rbenv·ruby2.6.5·rails 5.2.6
深夜情感老师3 小时前
centos离线安装ssh
linux·centos·ssh
夸克App5 小时前
实现营销投放全流程自动化 超级汇川推出信息流智能投放产品“AI智投“
运维·人工智能·自动化
Rainbond云原生5 小时前
83k Star!n8n 让 AI 驱动的工作流自动化触手可及
运维·人工智能·自动化
木觞清5 小时前
深度对比评测:n8n vs Coze(扣子) vs Dify - 自动化工作流工具全解析
运维·自动化
中云时代-防御可测试-小余5 小时前
高防IP是如何防护DDoS攻击和CC攻击的
运维·服务器·tcp/ip·安全·阿里云·ddos·宽度优先
网硕互联的小客服6 小时前
如何模拟黑客攻击(Red Teaming)以测试服务器安全性
运维·服务器
foo1st6 小时前
JDK(Ubuntu 18.04.6 LTS)安装笔记
java·笔记·ubuntu
樽酒ﻬق6 小时前
Kubernetes 常用运维命令整理
运维·容器·kubernetes
菜鸟射手7 小时前
QT creater和vs2017文件路径问题
linux·c++·windows·qt