centerOS 添加用户 和ubuntu 添加用户小区别

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 的家目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值