ubuntu中useradd和adduser究竟怎么用—用户管理一

来源:互联网 发布:unity3d培训机构那个好 编辑:程序博客网 时间:2024/05/21 22:32

在使用ubuntu的时候,稍微懂得点常识的童鞋都知道需要另创建一个用户方便自己以后操作,而不是直接使用超级用户root执行操作。不少人当然包括walfred在内创建新用户的时候基本上会先使用useradd命令。

可是useradd命令新手暂时还是不用的好,在ubuntu中创建新用户walfred推荐使用adduser命令:

walfred@ubuntu:~$ adduser newuser

adduser: Only root may add a user or group to the system.

walfred@ubuntu:~$ sudo adduser newuser

Adding user `newuser' ...

Adding new group `newuser' (1001) ...

Adding new user `newuser' (1001) with group `newuser' ...

Creating home directory `/home/newuser' ...

Copying files from `/etc/skel' ...

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

Changing the user information for newuser

Enter the new value, or press ENTER for the default

        Full Name []: newuer

        Room Number []:

        Work Phone []:

        Home Phone []:

        Other []:

Is the information correct? [Y/n] y

walfred@ubuntu:~$

使用adduser之后你享受到的将是一条龙服务,用户主目录自动生成以及密码、信息啥的都会依次提示你去完善,所以万无一失。但是高手却觉得很唐僧了,输入了这么多次,真麻烦,所以他们一般使用useradd命令,正确的使用useradd命令将会省去这么多的麻烦,一条语句就ok,所以说高手不一般的就在这边,哈哈,我会,但是我不是高手,not at all

先看下参数:

walfred@ubuntu:~$ useradd -h

useradd: invalid option -- 'h'

Usage: useradd [options] LOGIN

 

Options:

  -b, --base-dir BASE_DIR      base directory for the home directory of the

                               new account

  -c, --comment COMMENT        GECOS field of the new account

  -d, --home-dir HOME_DIR      home directory of the new account

  -D, --defaults               print or change default useradd configuration

  -e, --expiredate EXPIRE_DATE expiration date of the new account

  -f, --inactive INACTIVE      password inactivity period of the new account

  -g, --gid GROUP              name or ID of the primary group of the new

                               account

  -G, --groups GROUPS          list of supplementary groups of the new

                               account

  -h, --help                   display this help message and exit

  -k, --skel SKEL_DIR          use this alternative skeleton directory

  -K, --key KEY=VALUE          override /etc/login.defs defaults

  -l, --no-log-init            do not add the user to the lastlog and

                               faillog databases

  -m, --create-home            create the user's home directory

  -M, --no-create-home         do not create the user's home directory

  -N, --no-user-group          do not create a group with the same name as

                               the user

  -o, --non-unique             allow to create users with duplicate

                               (non-unique) UID

  -p, --password PASSWORD      encrypted password of the new account

  -r, --system                 create a system account

  -s, --shell SHELL            login shell of the new account

  -u, --uid UID                user ID of the new account

  -U, --user-group             create a group with the same name as the user

  -Z, --selinux-user SEUSER    use a specific SEUSER for the SELinux user mapping

useradd是通用Linux发行版本的命令,所以这条命令才是王道:

walfred@ubuntu:~$ sudo useradd -m -N newuser

walfred@ubuntu:~$ passwd newuser

passwd: You may not view or modify password information for newuser.

walfred@ubuntu:~$ sudo passwd newuser

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

可是我暂时还不知道如何一次性创建密码,麻烦知者赐教!

返回嵌入式入门专辑目录

原创粉丝点击