how to change a user home directory to adirectory that already exits?

15,075

The message is only informational - the change should be accepted regardless.

Ex. given

$ getent passwd testuser
testuser:x:1001:1001:,,,,[email protected]:/home/testuser:/bin/sh

then

$ sudo mkdir /home/foo 
$ sudo usermod -m -d /home/foo testuser
usermod: directory /home/foo exists

however the home directory was successfully changed

$ getent passwd testuser
testuser:x:1001:1001:,,,,[email protected]:/home/foo:/bin/sh

And just to be sure:

$ su - testuser
Password: 
$ pwd
/home/foo
Share:
15,075
j0h
Author by

j0h

been using Linux since 2005. Ubuntu since whenever edgy eft was new. Lucid Lynx Ubuntu was the best Ubuntu I have ever used.

Updated on September 18, 2022

Comments

  • j0h
    j0h over 1 year

    I have a website user who I want to be able to upload content to a folder on my server. I thought ok, I'll create a new user, and change his home directory to the folder where his stuff is already.

    No such luck, usermod wont allow me to create that directory, it already exists.

    $ sudo usermod -m -d /public_html/user user
      usermod: directory /public_html/user exists
    

    I looked through the man page but did not see an immediate solution to this problem.

    • Rinzwind
      Rinzwind almost 6 years
      Ehm, sorry but no. Just no. The horror stories I can tell where a windows admin decides to open /home/ as share where the user shift-deletes the files starting with a dot. Users need to be in /home and outside a webserver. You should create a symlink in /home/$USER/, force the user into that folder and connect that to /public_html/user