user that exists doesn't exist when setting chroot with usermod

Solution 1:

The -R flag on chroot, runs everything inside a chroot environment, it says the user does not exist because it is looking for the passwd file inside /home/user4/etc/ which probably does not exist.

The command you want is probably sudo usermod -d /home/user4 user4 to change the home directory.

To enforce a sandboxed environment where the user see's /home/user4 as their own root path is not managed by the passwd file or usermod command.

Some more information here.

https://help.ubuntu.com/community/BasicChroot