今天公司一同事新装的系统没有独立设置分区(没有区分home分区和根分区),整个系统在一个分区,这样系统升级或新安装很容易破坏用户数据(通常在home目录下)。
因此考虑将其他分区mount到他的home目录下的一个子目录,然后所有工作都在这个子目录(类似windows下的D,E等用户盘)。
后来想到如果可以更改已有用户的home目录则更好,下面搜集了一些更改用户home目录的信息,有空可以测试一下。注意:这些操作有一些风险,最好是在新系统或测试系统上测试。
Unix / Linux change a user's home directory - usermod
To change the user's home directory, just use the 'usermod' command, which exists on all unices. It works like this:
usermod -d /path/to/new/homedir/ username
Linux Change Default User Home Directory While Adding A New User
Q. By default user is added to /home directory. I'd like to add user to /iscsi/home/${user} directory instead of default /home. How do I force useradd to add user to /iscsi/home under CentOS / RHEL / Fedora Linux?
A. Default values for account creation defined in /etc/default/useradd file under CentOS / RHEL / Fedora / Debian / Ubuntu and other Linux distros. Simply open this file using a text editor:
# vi /etc/default/useradd
The default home directory defined by HOME variable, find line that read as follows:
HOME=/home
Replace with:
HOME=/iscsi/user
Save and close the file. Now you can add user using regular useradd command:
# useradd vivek
# passwd vivek
Verify user information:
# finger vivek
Output:
Login: vivek Name: Vivek Gite
Directory: /iscsi/user/vivek
Shell: /bin/bash
Last login Thu Sep 13 07:58 2007 (IST) on pts/1 from 10.16.15.2
No mail.
No Plan.