3

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.

muru
  • 197,895
  • 55
  • 485
  • 740
j0h
  • 14,825
  • 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 – Rinzwind Jul 27 '18 at 14:30

1 Answers1

7

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

Ex. given

$ getent passwd testuser
testuser:x:1001:1001:,,,,testuser@foo.com:/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:,,,,testuser@foo.com:/home/foo:/bin/sh

And just to be sure:

$ su - testuser
Password: 
$ pwd
/home/foo
steeldriver
  • 136,215
  • 21
  • 243
  • 336