centerOS添加用户
查看系统版本
[root@host-192-168-79-20 home]# uname -a
Linux host-192-168-79-20 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@host-192-168-79-20 home]#
centerOS添加用户 【不用-m 选项】
[root@host-192-168-79-20 home]# ll
total 0
drwxr-xr-x 4 admin admin 128 Mar 24 06:08 admin
[root@host-192-168-79-20 home]# useradd test
[root@host-192-168-79-20 home]# ll
total 0
drwxr-xr-x 4 admin admin 128 Mar 24 06:08 admin
drwx------ 3 test test 78 Mar 25 00:04 test
[root@host-192-168-79-20 home]#
centerOS添加用户 【用-m 选项】
[root@host-192-168-79-20 home]# ll
total 0
drwxr-xr-x 4 admin admin 128 Mar 24 06:08 admin
drwx------ 3 test test 78 Mar 25 00:04 test
[root@host-192-168-79-20 home]# useradd -m test_two
[root@host-192-168-79-20 home]# ll
total 0
drwxr-xr-x 4 admin admin 128 Mar 24 06:08 admin
drwx------ 3 test test 78 Mar 25 00:04 test
drwx------ 3 test_two test_two 78 Mar 25 00:06 test_two
[root@host-192-168-79-20 home]#
useradd -m xiaoran; echo “123456” | passwd --stdin “xiaoran”
useradd -m 用户名;echo “密码” | passwd --stdin “用户名”
-m # 添加用户同时添加家目录
centerOS 添加用户时,不加 -m 选项,默认也会在/home下添加自己的家目录
centerOS添加用户时指定密码
[root@host-192-168-79-20 home]# useradd -m xiaoran; echo "123456" | passwd --stdin "xiaoran"
Changing password for user xiaoran.
passwd: all authentication tokens updated successfully.
[root@host-192-168-79-20 home]# ll
total 0
drwxr-xr-x 4 admin admin 128 Mar 24 06:08 admin
drwx------ 3 xiaoran xiaoran 78 Mar 25 01:00 xiaoran
[root@host-192-168-79-20 home]#
ubuntu添加用户
ubuntu 添加用户 如果同时还要家目录的话,必须加 -m 选项
测试系统版本
root@xiaoran:/home# uname -a
Linux xiaoran 5.4.0-67-generic #75-Ubuntu SMP Fri Feb 19 18:03:59 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
root@xiaoran:/home#
ubuntu添加用户【使用-m选项】
useradd -m test
root@xiaoran:/home# ll
total 28
drwxr-xr-x 7 root root 4096 Mar 25 11:38 ./
drwxr-xr-x 22 root root 4096 Mar 25 10:52 ../
drwxr-xr-x 2 root root 4096 Mar 25 10:49 backup_file/
drwxr-xr-x 5 root root 4096 Mar 15 10:02 docker/
drwxr-xr-x 2 goudaner goudaner 4096 Mar 25 11:38 goudaner/
drwxr-xr-x 3 root root 4096 Mar 10 10:50 hadmin/
drwxr-xr-x 5 xiaoran xiaoran 4096 Mar 18 16:14 xiaoran/
root@xiaoran:/home# useradd -m test
root@xiaoran:/home# ll
total 32
drwxr-xr-x 8 root root 4096 Mar 25 11:56 ./
drwxr-xr-x 22 root root 4096 Mar 25 10:52 ../
drwxr-xr-x 2 root root 4096 Mar 25 10:49 backup_file/
drwxr-xr-x 5 root root 4096 Mar 15 10:02 docker/
drwxr-xr-x 2 goudaner goudaner 4096 Mar 25 11:38 goudaner/
drwxr-xr-x 3 root root 4096 Mar 10 10:50 hadmin/
drwxr-xr-x 2 test test 4096 Mar 25 11:56 test/
drwxr-xr-x 5 xiaoran xiaoran 4096 Mar 18 16:14 xiaoran/
root@xiaoran:/home#
从上边可以看出/home 下多了一个test 的文件夹,这个test目录就是test用户的家目录
ubuntu添加用户【不使用-m选项】
useradd test_two
root@xiaoran:/home# ll
total 32
drwxr-xr-x 8 root root 4096 Mar 25 11:56 ./
drwxr-xr-x 22 root root 4096 Mar 25 10:52 ../
drwxr-xr-x 2 root root 4096 Mar 25 10:49 backup_file/
drwxr-xr-x 5 root root 4096 Mar 15 10:02 docker/
drwxr-xr-x 2 goudaner goudaner 4096 Mar 25 11:38 goudaner/
drwxr-xr-x 3 root root 4096 Mar 10 10:50 hadmin/
drwxr-xr-x 2 test test 4096 Mar 25 11:56 test/
drwxr-xr-x 5 xiaoran xiaoran 4096 Mar 18 16:14 xiaoran/
root@xiaoran:/home# useradd test_two
root@xiaoran:/home# ll
total 32
drwxr-xr-x 8 root root 4096 Mar 25 11:56 ./
drwxr-xr-x 22 root root 4096 Mar 25 10:52 ../
drwxr-xr-x 2 root root 4096 Mar 25 10:49 backup_file/
drwxr-xr-x 5 root root 4096 Mar 15 10:02 docker/
drwxr-xr-x 2 goudaner goudaner 4096 Mar 25 11:38 goudaner/
drwxr-xr-x 3 root root 4096 Mar 10 10:50 hadmin/
drwxr-xr-x 2 test test 4096 Mar 25 11:56 test/
drwxr-xr-x 5 xiaoran xiaoran 4096 Mar 18 16:14 xiaoran/
root@xiaoran:/home#
从上边的代码段中可以看出,如果不使用-m选项的话,/home 下边不会有对应新增用户 test_two 的家目录