LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 03-11-2017, 01:00 PM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Rep: Reputation: Disabled
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.
 
Old 03-11-2017, 01:07 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
usermod -md /home/home0/lisa1 lisa1
 
Old 03-11-2017, 02:00 PM   #3
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydrurga View Post
usermod -md /home/home0/lisa1 lisa1
Did not work.
Did you try it?
 
Old 03-11-2017, 02:24 PM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Quote:
Originally Posted by fanoflq View Post
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.
 
Old 03-11-2017, 02:40 PM   #5
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydrurga View Post
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.
 
Old 03-11-2017, 03:03 PM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
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.
Old 03-11-2017, 03:28 PM   #7
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydrurga View Post
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 ?
Code:
-bash-4.2$
 
Old 03-11-2017, 03:44 PM   #8
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
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.
Old 03-11-2017, 03:47 PM   #9
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
@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.
 
Old 03-11-2017, 04:08 PM   #10
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Quote:
Originally Posted by fanoflq View Post
@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 .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
move /home directory before upgrade??? Adrian Baker Linux - General 2 12-18-2006 08:21 AM
Move /home directory on RAID5 elyounsi SUSE / openSUSE 3 12-07-2005 12:10 PM
Move my Home directory... it-s Linux - General 5 07-08-2005 11:34 AM
Move home directory iain.ross Linux - Newbie 6 01-01-2005 04:37 PM
move postgres home directory how to? vickr1z Linux - Newbie 2 09-15-2004 11:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration