Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-11-2017, 01:00 PM
|
#1
|
Member
Registered: Nov 2015
Posts: 397
Rep: 
|
Not able to move a user's home directory
#Want to move user lisa1 home directory, /home/lisa1 to
# to reside in new parent home directory, /home/home0,
as in /home/home0/lisa1.
Code:
[root@Centos7-1024ram-minimal home]# ls
lisa0 lisa1 user1 user2
[root@Centos7-1024ram-minimal home]# mkdir home0
[root@Centos7-1024ram-minimal home]# usermod -md /home/home0 lisa1
usermod: directory /home/home0 exists
[root@Centos7-1024ram-minimal home]# ls -l /home/home0
total 0
[root@Centos7-1024ram-minimal home]#
From man usermod:
Quote:
-d, --home HOME_DIR
The user's new login directory.
If the -m option is given, the contents of the
current home directory will be moved to the new
home directory, which is created if it does not
already exist. If the current home directory does
not exist the new home directory will not be created.
-m, --move-home
Move the content of the user's home directory to the new location.
|
Why is it not working?
Last edited by fanoflq; 03-11-2017 at 04:28 PM.
|
|
|
03-11-2017, 01:07 PM
|
#2
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
usermod -md /home/home0/lisa1 lisa1
|
|
|
03-11-2017, 02:00 PM
|
#3
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
Quote:
Originally Posted by hydrurga
usermod -md /home/home0/lisa1 lisa1
|
Did not work.
Did you try it?
|
|
|
03-11-2017, 02:24 PM
|
#4
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Quote:
Originally Posted by fanoflq
Did not work.
Did you try it?
|
You said that you wanted the user's home directory to become /home/home0/lisa1. Your command, as originally stated, directed that the home directory of user lisa1 become /home/home0.
That's what I was pointing out.
|
|
|
03-11-2017, 02:40 PM
|
#5
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
Quote:
Originally Posted by hydrurga
You said that you wanted the user's home directory to become /home/home0/lisa1. Your command, as originally stated, directed that the home directory of user lisa1 become /home/home0.
That's what I was pointing out.
|
The option -m will copy directory lisa1 and its subdirectories to
/home/hme0.
But that did not happen.
Code:
[root@Centos7-1024ram-minimal home]# ls
home0 lisa0 lisa1 user1 user2
[root@Centos7-1024ram-minimal home]# ls -al home0
total 0
drwxr-xr-x. 2 root root 6 Mar 11 12:58 .
drwxr-xr-x. 7 root root 66 Mar 11 11:50 ..
[root@Centos7-1024ram-minimal home]# usermod -md /home/home0/lisa1 lisa1
usermod: no changes
[root@Centos7-1024ram-minimal home]# ls -al home0
total 0
drwxr-xr-x. 2 root root 6 Mar 11 12:58 .
drwxr-xr-x. 7 root root 66 Mar 11 11:50 ..
The command did not work.
Neither did this command:
Quote:
usermod -md /home/home0 lisa1
|
That was my original question.
Last edited by fanoflq; 03-11-2017 at 02:42 PM.
|
|
|
03-11-2017, 03:03 PM
|
#6
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
I've just been trying it out on a test box and have to admit that the -m option is doing nothing for me too.
In the end I created the new directory folder at /home/home0/lisa1, recursively copied everything over from the old home directory to the new directory, chown -R lisa1:lisa1 /home/home0/lisa1, then usermod -d /home/home0/lisa1 lisa1. I then logged out and back in again as lisa1. All worked ok. It still doesn't explain why the usermod -m option wouldn't work though.
Last edited by hydrurga; 03-11-2017 at 03:35 PM.
Reason: Changed order - apologies
|
|
1 members found this post helpful.
|
03-11-2017, 03:28 PM
|
#7
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
Quote:
Originally Posted by hydrurga
I've just been trying it out on a test box and have to admit that the -m option is doing nothing for me too.
In the end I created the new directory folder at /home/home0/lisa1, ran chown -R lisa1:lisa1 /home/home0/lisa1, recursively copied everything over from the old home directory to the new directory, then usermod -d /home/home0/lisa1 lisa1. I then logged out and back in again as lisa1. All worked ok. It still doesn't explain why the usermod -m option wouldn't work though.
|
Thank you.
Do you think it is a bug?
The -d option works!
Take a look here:
Code:
[root@Centos7-1024ram-minimal ~]# echo $HOME
/root
[root@Centos7-1024ram-minimal ~]# ls /home
home0 lisa0 lisa1 user1 user2
[root@Centos7-1024ram-minimal ~]# mkdir /home/home0/lisa1
[root@Centos7-1024ram-minimal ~]# ls /home/home0
lisa1
[root@Centos7-1024ram-minimal ~]# usermod -d /home/home0/lisa1 lisa1
[root@Centos7-1024ram-minimal ~]# su - lisa1
Last login: Sat Mar 11 14:16:48 MST 2017 on pts/0
-bash-4.2$ pwd
/home/home0/lisa1
-bash-4.2$ echo $HOME
/home/home0/lisa1
Why does it go into this prompt after command : su - lisa1 ?
|
|
|
03-11-2017, 03:44 PM
|
#8
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Just a note to say that I changed the order of the commands in post #6 to ensure that all the directories and files copied over to the new home directory are brought back under lisa1's ownership if for some reason they aren't.
I don't know if it is a bug but the -m option certainly doesn't appear to work for me. The -d option appears to correctly change the user's home directory details stored in /etc/passwd.
The home directory normally includes .bashrc that controls how the prompt is displayed. In your case, the new home directory does not yet contain any files. So, if you recursively copy all the files over to the new home directory (and ensure that they are all owned by lisa1) before issuing the su command, then the proper prompt should be displayed.
|
|
1 members found this post helpful.
|
03-11-2017, 03:47 PM
|
#9
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
@hydrurga:
Quote:
I don't know if it is a bug but the -m option certainly doesn't appear to work for me.
|
Same here.
Thank you.
It should be reported to the author.
But there is no author on the usermod man page.
Last edited by fanoflq; 03-11-2017 at 03:51 PM.
|
|
|
03-11-2017, 04:08 PM
|
#10
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Quote:
Originally Posted by fanoflq
@hydrurga:
Same here.
Thank you.
It should be reported to the author.
But there is no author on the usermod man page.
|
Of course it might be that we're both just misunderstanding or misusing the command.
usermod is supplied by the passwd package, which in my case is maintained by Ubuntu. I'm not sure what the setup for CentOS is, but I imagine that it is maintained by the CentOS guys. The CentOS bug tracker is at https://bugs.centos.org/main_page.php .
|
|
|
All times are GMT -5. The time now is 11:36 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|