How do I change user name (rename user name) or UID under a Linux operating system using command line tools?
You need to use the usermod command to change user name under a Linux operating systems. This command modifies the system account files to reflect the changes that are specified on the command line. Do not edit /etc/passwd file by hand or using a text editor such as vi.
Syntax
The syntax is as follows to rename by user name:
usermod -l login-name old-name
Where,
- The name of the user will be changed from old-name to login_name. Nothing else is changed. In particular, the user’s home directory name should probably be changed to
reflect the new login name.
The syntax is as follows to rename by a UID (user ID):
usermod -u UID username
Where,
- The numerical value of the user’s ID (UID) . This value must be unique, unless the -o option is used. The value must be non-negative. Values between 0 and 99 are typically reserved for system accounts. Any files which the user owns and which are located in the directory tree rooted at the user’s home directory will have the file user ID changed automatically. Files outside of the user’s home directory must be altered
manually.
Examples
Let us see how to rename user login. First, make sure user is not logged into the server and any other process is not running under the same user name. I also recommend that you backup any data or server files before changing user names.
Task: View current user and group memebership for user named tom
The syntax is as follows:
# get tom ids id tom # see login info grep ^tom: /etc/passwd # see group info grep ^tom: /etc/group # See home dir permissions ls -ld /home/tom/ # See process owned by tom user/group ps aux | grep tom ps -u tom |
Sample outputs:
Task: Change username from tom to jerry
Type the usermod command as follows:
# id tom
# usermod -l jerry tom
## Verify ###
# id tom
# id jerry
# ls -ld /home/tom
A note about running process
You may see an error as follows if tom is logged in and running jobs:
# usermod -l jerry tom usermod: user tom is currently used by process 6886
You need to kill all process owned by tom user and forcefully logged him out of the system:
# pkill -u tom pid # pkill -9 -u tom # usermod -l jerry tom
Task: Change primary groupname from tom to jerry
Type the usermod command as follows:
# id tom
# groupmod -n jerry tom
## Verify ###
# id tom
# ls -ld /home/tom
Sample outputs:
Task: User home directory from /home/tom/ to /home/jerry
The syntax is:
# usermod -d /home/jerry -m jerry
# id jerry
# ls -ld /home/jerry
Sample outputs:
uid=1001(jerry) gid=1001(jerry) groups=1001(jerry) drwxr-xr-x 2 jerry jerry 4096 Apr 21 15:53 /home/jerry/
Task: Change user tom UID from 5001 to 10000
Type the usermod command as follows:
# id tom
# usermod -u 10000 tom
# id tom
Read man pages of usermod(8) and groupmod(8) commands for more information.
fonte: https://www.cyberciti.biz/faq/howto-change-rename-user-name-id/
No linux mint xfce, ocorreu que ao fazer login com nome de usuario alterado, perde-se todos os icones/barra de menus, da área de trabalho.
Para resolver esse problema, na pasta de usuário, dentro das pasta ~/.config/xfce4, altere o direcionamento da pasta com username antigo para novo (/home/userantigo /home/usernovo) e após isso, execute o comando para reiniciar o painel XFCE ( xfce4-panel -r)