增加用户

useradd 命令

在 root 权限下,通过 useradd 命令可以为系统添加新用户信息,其中 options 为相关参数,user_name 为用户名称。

useradd [options] user_name

用户信息文件

与用户账号信息有关的文件如下:

  • /etc/passwd:用户账号信息文件。
  • /etc/shadow:用户账号信息加密文件。
  • /etc/group:组信息文件。
  • /etc/defaut/useradd:定义默认设置文件。
  • /etc/login.defs:系统广义设置文件。
  • /etc/skel:默认的初始配置文件目录。

创建用户实例

例如新建一个用户名为 user_example 的用户,在 root 权限下执行如下命令:

# useradd user_example

说明:

没有任何提示,表明用户建立成功。这时并没有设置用户的口令,请使用 passwd 命令修改用户的密码,没有设置密码的新账号不能登录系统。

使用 id 命令查看新建的用户信息,命令如下:

# id user_example
uid=502(user_example)    gid=502(user_example)    groups=502(user_example)

修改用户 user_example 的密码:

# passwd user_example

根据提示两次输入新用户的密码,完成密码更改。过程如下:

# passwd user_example
Changing password for user user_example.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

说明:

若打印信息中出现“BAD PASSWORD: The password fails the dictionary check - it is too simplistic/sytematic”,表示设置的密码过于简单,建议设置复杂度较高的密码。

results matching ""

    No results matching ""