2

After copying all contents of a user home directory I'm trying to change the home directory to the new location. But systemd prevents me from doing this.

# sudo usermod -d /data/home/user/ user
usermod: user user is currently used by process 10050
# sudo ps -fp  10050
UID          PID    PPID  C STIME TTY          TIME CMD
user       10050       1  0 Nov23 ?        00:00:03 /usr/lib/systemd/systemd --user

How can I achieve this ?

I'd like to avoid stopping services or rebooting the server just to move a home directory

The user is not logged on, I checked using sudo who

cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.5 (Ootpa)
carl verbiest
  • 471
  • 4
  • 11
  • Does https://unix.stackexchange.com/a/321096/70524 help? – muru Dec 05 '22 at 11:35
  • Did not work in Linux Mint. I can see the sessions with "sudo loginctl list-sessions" but when I try to termintate the session, it does nothing - also no error msg. – Manuel Manhart Apr 24 '23 at 12:17

2 Answers2

3

You can forcefully logout the user via

sudo pkill -KILL -u {username}

After that your user should be free, you can check with

sudo loginctl list-sessions

and the usermod command should work.

Manuel Manhart
  • 201
  • 2
  • 5
1

did you try using -m option with -d ?

sudo usermod user -m -d /data/home/user/
csx4
  • 333
  • 2
  • 6