改变家目录

-bash-4.1# grep ^root /etc/passwd
root:x:0:0:root:/data1/apps:/bin/bash
#注意家目录改变前一定要把密钥也同时移到新的家目录里
-bash-4.1# cd ~
-bash-4.1# pwd
/data1/apps
-bash-4.1# ls -all
total 20
drwxr-xr-x 3 root root 4096 Feb 20 09:24 .
drwxr-xr-x 3 root root 4096 Feb 19 23:59 ..
-rw------- 1 root root  193 Feb 20 09:23 .bash_history
drwxr-xr-x 2 root root 4096 Feb 20 09:23 .ssh
-rw------- 1 root root 1900 Feb 20 09:24 .viminfo

 新建用户test

[root@86 ~]# useradd test
[root@86 ~]# passwd test
Changing password for user test.
New password: 
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@86 ~]# id test
uid=505(test) gid=505(test) groups=505(test)
[root@86 ~]# usermod -d /tmp/ test
[root@86 ~]# su - test
-bash-4.1$ pwd
/tmp/

但usermod命令对root没有用,只能对普通用户。对root来说应该只有一种方法,就是直接修改/etc/passwd

原文地址:https://www.cnblogs.com/bass6/p/6418194.html