用户创建

创建一个 拥有 root 权限的用户

  1. #!/usr/bin/env bash
  2. __create_root_user() {
  3. # 创建一个 拥有 root 权限的用户
  4. _username="lwm"
  5. _password=$(openssl rand -hex 12)
  6. useradd -o -u 0 -g 0 -M -d /root -s /bin/bash "$_username" 2>/dev/null # 创建用户
  7. echo "$_password" | passwd --stdin "$_username" # 重置密码
  8. echo "用户名: $_username"
  9. echo "密 码: $_password"
  10. }
  11. __create_root_user

密码相关

重置root账户密码为 passwde

  1. echo passwd | passwd --stdin root

设置本地用户进入系统免密码

  1. sed -i 's,^ExecStart=.*$,ExecStart=-/sbin/agetty --autologin root --noclear %I,' /etc/systemd/system/getty.target.wants/getty@tty1.service