zoukankan      html  css  js  c++  java
  • linux环境中通过useradd命令,创建用户的时候指定用户的base-dir

    需求说明:

      今天一个同事,问了一个这样的问题,在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系统下ping命令报错 name or service not know
    利用Kettle进行SQLServer与Oracle之间的数据迁移实践
    STS中配置MyBatis代码生成器
    GeoServer中配置GeoWebCache切片缓存目录
    Win10下安装msi程序包时报2503、2502错误问题及其解决办法
    常用办公软件推荐
    Excel中使用VBA进行度分秒与十进制度的转换
    ArcGIS下图层范围不正确的两种处理方式
    更改GeoServer的端口号
    Tomcat跨域访问配置
  • 原文地址:https://www.cnblogs.com/chuanzhang053/p/9778239.html
Copyright © 2011-2022 走看看