如何更改linux 用户的home目录

      今天公司一同事新装的系统没有独立设置分区(没有区分home分区和根分区),整个系统在一个分区,这样系统升级或新安装很容易破坏用户数据(通常在home目录下)。

      因此考虑将其他分区mount到他的home目录下的一个子目录,然后所有工作都在这个子目录(类似windows下的D,E等用户盘)。

      后来想到如果可以更改已有用户的home目录则更好,下面搜集了一些更改用户home目录的信息,有空可以测试一下。注意:这些操作有一些风险,最好是在新系统或测试系统上测试。

 

 

Unix / Linux change a user's home directory - usermod

I watched somebody change a user's home directory today by deleting the user using 'userdel' and then re-creating the user with 'adduser' and entering a different path for their home directory. This is not the simplest way to do it..

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

by Vivek Gite on May 5, 2008 · 7 comments

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值