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

  • 相关阅读:
    Unable to lock the administration directory (/var/lib/dpkg/)解决办法
    Linux实训——搭建动态网站
    Linux实训——搭建HTTP服务器
    小程序学习视频教程
    数组的所有方法
    小程序组件封装步骤
    微信小程序生成图片学习
    小程序组件封装学习地址
    开发者在 onPageNotFound 回调中进行重定向处理onPageNotFound(Object)
    小程序中view的自定义属性获取
  • 原文地址:https://www.cnblogs.com/chuanzhang053/p/9778239.html
Copyright © 2011-2022 走看看