Manage users under Linux
Create user using CLI
Interactive mode
sudo adduser claude
Then you have to answer severals questions
Adding user `claude' ...
Adding new group `claude' (1001) ...
Adding new user `claude' (1001) with group `claude' ...
The home directory `/home/claude' already exists. Not copying from `/etc/skel'.
adduser: Warning: The home directory `/home/claude' does not belong to the user you are currently creating.
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for claude
Enter the new value, or press ENTER for the default
Full Name []: Real name
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
None interactive mode
TODO
sudo adduser --home /home/nathan/ nathan
Moving user home directory (need to be reviewed)
Let say you want to move users directories on
a new partition /mnt/data/
To avoid confusion create a home
folder and then usermod
will handle everything (target folder should not exist).
sudo mkdir -p /mnt/data/home
sudo chmod 755 /mnt/data
sudo chmod 755 /mnt/data/home
From here you have two options:
Moving user home in /etc/passwd
# for current user
sudo usermod -m -d /mnt/data/home/${USER} ${USER}
# for a user named 'claude' (Warn user must exist)
sudo usermod -m -d /mnt/data/home/claude claude
Then if you want to be sure everything is working on the new location (if have some configured application using /home/claude for instance)
# for current user
sudo ln -s /mnt/data/home/${USER} /home/${USER}
# for a user named 'claude'
sudo ln -s /mnt/data/home/claude /home/claude
Double check you have created expected link using
ls --color -lF /home
Moving user home using symbolic links
Another option (my favorite) is to keep /etc/passwd
using /home/USERDIR
and create
Link
Restoring a user home
cp -dr <PREVIOUS_BACKUP> <DESTINATION>
Notice warning in log, it that situation it look like you have restore user account, so after this you need to fix rights access:
Basically you need to run chown
sudo chown -R claude:claude /home/claude/
# OR (depending of your previous choice)
sudo chown -R claude:claude /mnt/data/home/claude/
-R
for recurse acionclaude:claude
to set userid and groupid for all files/home/claude/
or/mnt/data/home/claude/
real home folder localtion