码迷,mamicode.com
首页 > 系统相关 > 详细

linux环境中通过useradd命令,创建用户的时候指定用户的base-dir

时间:2018-10-12 16:02:04      阅读:1193      评论:0      收藏:0      [点我收藏+]

标签:同名   ISE   rect   div   defaults   查看   root   nat   一个   

需求说明:

  今天一个同事,问了一个这样的问题,在linux环境中,创建用户的时候,默认的是在/home目录下创建一个与用户名相同的家目录,

  如何能够将这个/home更换成一个其他的,比如/opt/app下,研究了下,在此记录下

操作过程:

1.通过查看useradd命令的帮助文档,知道创建用户base_dir的配置在/etc/default/useradd文件中

[root@testvm01 ~]# cat /etc/default/useradd 
# useradd defaults file
GROUP=100
HOME=/home  #这个就是BASE_DIR,那么每次都是在/home下创建一个与用户名同名的家目录.
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

2.修改这个配置

[root@testvm01 ~]# cat /etc/default/useradd 
# useradd defaults file
GROUP=100
HOME=/opt/app   #目录已经进行修改
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

3.创建新的用户,查看用户的家目录位置

[root@testvm01 ~]# useradd testhome
[root@testvm01 ~]# cat /etc/passwd | grep testhome
testhome:x:803:803::/opt/app/testhome:/bin/bash
[root@testvm01 ~]# su - testhome
[testhome@testvm01 ~]$ pwd
/opt/app/testhome

备注:测试成功,新建的用户都是在/opt/app下建的目录,切换用户之后,通过pwd看到的也是相同的目录

 

useradd的帮助命令:

       -b, --base-dir BASE_DIR
           The default base directory for the system if -d HOME_DIR is not specified.  BASE_DIR is concatenated with the account name to define the home directory. The
           BASE_DIR must exist otherwise the home directory cannot be created.

           If this option is not specified, useradd will use the base directory specified by the HOME variable in /etc/default/useradd, or /home by default.

 

注意:对于不熟悉的操作,可以首先查看man获得一些基本的信息.

 

文档创建时间:2018年10月12日15:07:32

linux环境中通过useradd命令,创建用户的时候指定用户的base-dir

标签:同名   ISE   rect   div   defaults   查看   root   nat   一个   

原文地址:https://www.cnblogs.com/chuanzhang053/p/9778239.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!