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

Solution 1:

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