Labels

Tuesday, November 22, 2011

How to change user's home directory and user name, and delete user and all files in Ubuntu

1. To change the user's home directory
sudo usermod -d /path/of/new/home -m username

will copy all files from user's home directory to /path/to/new/home and will also update the system file that stores the location of user's home directory (/etc/passwd).


2. to change the username (used as username in the system) and the user’s real name (usually is a displayed name).

sudo usermod -c "Real Name" -l New_Username Old_Username


3. Deleting a User from an Ubuntu Linux System

3.1 An existing user may be deleted using the same User settings dialog used to add a user as outlined above. Select the System desktop menu and choose Users and Groups from the Administration sub-menu to launch the User settings dialog.

Select the user to be deleted and click on Delete. A confirmation dialog will appear. If you wish to proceed click on Delete in the confirmation dialog to commit the change.

Note that the deletion process will remove the account but leave the user's home directory intact. This will need to be deleted manually if it, and any files therein, are no longer required.


3.2 A user account may also be deleted from command-line using the deluser utility:

sudo deluser john


3.3 It is also possible to remove the user's home directory as part of the deletion process:

sudo deluser --remove-home john

Alternatively all files owned by the user, including those in the user's home directory may be removed as follows:

sudo deluser --remove-all-files john

The files in the user's home directory can also be backed up to another location before the directory is deleted using --backup-to command-line option together with the path to the backup directory:

sudo deluser --backup-to /oldusers/backups/john --remove-home john

No comments:

Post a Comment