linux环境中通过useradd命令,创建用户的时候指定用户的base-dir
生活随笔
收集整理的這篇文章主要介紹了
linux环境中通过useradd命令,创建用户的时候指定用户的base-dir
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
需求說明:
今天一個同事,問了一個這樣的問題,在linux環(huán)境中,創(chuàng)建用戶的時候,默認(rèn)的是在/home目錄下創(chuàng)建一個與用戶名相同的家目錄,
如何能夠?qū)⑦@個/home更換成一個其他的,比如/opt/app下,研究了下,在此記錄下
操作過程:
1.通過查看useradd命令的幫助文檔,知道創(chuàng)建用戶base_dir的配置在/etc/default/useradd文件中
[root@testvm01 ~]# cat /etc/default/useradd # useradd defaults file GROUP=100 HOME=/home #這個就是BASE_DIR,那么每次都是在/home下創(chuàng)建一個與用戶名同名的家目錄. INACTIVE=-1 EXPIRE= SHELL=/bin/bash SKEL=/etc/skel CREATE_MAIL_SPOOL=yes2.修改這個配置
[root@testvm01 ~]# cat /etc/default/useradd # useradd defaults file GROUP=100 HOME=/opt/app #目錄已經(jīng)進(jìn)行修改 INACTIVE=-1 EXPIRE= SHELL=/bin/bash SKEL=/etc/skel CREATE_MAIL_SPOOL=yes3.創(chuàng)建新的用戶,查看用戶的家目錄位置
[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_DIRThe 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. TheBASE_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獲得一些基本的信息.
?
文檔創(chuàng)建時間:2018年10月12日15:07:32
轉(zhuǎn)載于:https://www.cnblogs.com/chuanzhang053/p/9778239.html
總結(jié)
以上是生活随笔為你收集整理的linux环境中通过useradd命令,创建用户的时候指定用户的base-dir的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 快速将InnoDB表复制到另一个实例
- 下一篇: angle-class