Linux: How To Rename a user account

In this post you’ll see how to change user name or rename a user name in linux operating system, normally,  it is necessary to change users name who has already been created. of course, linux admin will receive this kinds of request from normal user to change him or her username to access the remote linux server, then how to change the user name.

You need to use linux command usermod to change the use name or rename use name. the syntax is as followss:

usermod [-c comment] [-d home_dir [ -m]]

               [-e expire_date] [-f inactive_time]

               [-g initial_group] [-G group[,...]]

               [-l login_name] [-s shell]

               [-u uid [ -o]] login

usermod -l < loginname> < oldname>

usermod -u <uid number> <username>

option “-l” means you need to give loginname and this command will change oldname to new login name.

option “-u” means that given a new uid number to user

Linux Rename User Name 


You know usemod command can be used to change user’s name or user’s uid number. let’s take a look some examples in below :

Change usernmae from “atest” to “ctest”, issue the following command:

usermod -l ctest atest

Output:

[root@localhost ~]# id atest


uid=503(atest) gid=503(atest) groups=503(atest) context=root:system_r:unconfined_t:SystemLow-SystemHigh

[root@localhost ~]# usermod -l ctest atest

[root@localhost ~]# id ctest

uid=503(ctest) gid=503(atest) groups=503(atest) context=root:system_r:unconfined_t:SystemLow-SystemHigh

You’ll see the above output, atest username has been changed to ctest.

Change UID number of ctest user to 800, type usermod command as followss:

usermod -u 800 ctest

Output:

[root@localhost ~]# id ctest

uid=503(ctest) gid=503(atest) groups=503(atest) context=root:system_r:unconfined_t:SystemLow-SystemHigh

[root@localhost ~]# 

[root@localhost ~]# usermod -u 800 ctest

[root@localhost ~]# id ctest

uid=800(ctest) gid=503(atest) groups=503(atest) context=root:system_r:unconfined_t:SystemLow-SystemHigh

 

You might also like:

Sidebar



back to top