Linux rename user and home

Renaming user name [duplicate]

I made a mistake in the username at the time of installation. So I changed the name of the user after logging in by creating a guest account with SUDO rights. But when I checked the list of users using ls /home command I am not seeing the new name for the user instead Old name is appearing. But I use the new name to login. Is it like I need to change the name inside Home directory separately? Also , if there is any other changes needs to be done .. ?

4 Answers 4

Procedure to rename or change username in Ubuntu:

If running as the user to be modified, logout first, then open a console:

Otherwise, simply open a new Terminal:

exec sudo -i killall -u [oldname] id [oldname] usermod -l [newname] [oldname] groupmod -n [newname] [oldname] usermod -d /home/[newname] -m [newname] usermod -c "[full name (new)]" [newname] id [newname] 
sudo -i killall -u belaje id belaje uid=1000(belaje) gid=1000(belaje) groups=1000(belaje),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),127(sambashare) usermod -l balaja belaje groupmod -n balaja belaje usermod -d /home/balaja -m balaja usermod -c "Bala Jagannathan" balaja id balaja 

Whenever you want to get back from console version to graphical version:

Using this procedure I successfully modified user account however only from another account (which I had to create for that purpose and later deleted). I wonder if that is the case (which is not mentioned actually) or I was doing something wrong? The main point was that «killall -u oldname» logged me out so that I couldn’t continue remaining steps.

This probably would be better done through a TTY, not a terminal emulator in GUI. So I’d replace the keyboard shortcut to terminal emulator with shortcut to TTY1, which is Ctrl + Alt + F1

Please add that if the user has an encrypted home directory, it’s also necessary to edit /home/newname/.ecryptfs/Private.mnt to point to the new home directory.

Instead of killall and usermod (which I didn’t want to do through an SSH connection with the logged-in user) I had success with changing the user name in /etc/passwd and /etc/shadow .

@BKSpurgeon Nope. After renaming the account, the new login is using the /home/oldname folder. You specify the new folder name and the user it’s for, so newname both times. linux.die.net/man/8/usermod

on the server this worked for me:

sudo usermod -md /home/NewHome -l NewName OldName sudo groupmod -n NewGroupName OldGroupName 

This renames the user and its group and also the home folder.

Читайте также:  Copy folder with all files linux

This works, but a lot of the apps will break because they specifically call for the /home/oldusername ; many individual software authors don’t use variables to call their configs, they directly specify oldusername not $HOME. Chrome, GTK and firefox break like this. Don’t forget your keyrings will have the old credentials as well. I’m not sure how to back those up. maybe export them?

So, I end up doing the following to change username — man i wish i knew an easier way.

  • as olduser , sign in to chrome and firefox to sync out the settings
  • using users and groups in Settings, create user killmenow with pass of same, make him admin, reboot and log in as killmenow .
  • open terminal, riun sudo i , then mkdir /home/newusername and making it the same uid:gid as the oldusername
  • Move usercreatedfiles.xyz, Desktop, Downloads, and other dirs containing created files like docs, pics, music, movies, etc in /home/oldusername/ to /home/newusername .
  • Find out any specific apps with particular settings. Helpful to pay attention here 🙂 user will likely bean you with a phonebook if you lose their files 😉
  • vi /etc/passwd and /etc/group to reference newusername and /home/newusername
  • passwd newusername and enter a temporary password twice reboot and log in as newusername , password being what you entered in the previous point.
  • delete killmenow using «users and groups» in Settings.

wait until some time passes before deleting /home/oldusername — in case you missed important stuff. or move it to /home/newusername/Downloads and tell them

mv /home/oldusername /home/newusername/Downloads/oldusername-backup 

Источник

How to rename Linux users and their home directory

In this tutorial, you will learn how to a rename a user in CentOS, Debian, Ubuntu and most other Linux distributions. More than that, you will also learn how to rename thier home directory, primary group, and change their UID.

Renaming Users in Linux

Linux provides a tool named usermod specifically for making modifications to user accounts. In this case we are using it to rename a user account, which is done using the -l flag.

For example, to rename a user named student1 to johndoe, you would run the usermod command as follows.

sudo usermod -l johndoe student1

The -l flag will only change the user’s name. All other things attached to the user will remain unaffected, such as home directory. and UID.

Changing a User’s Home Directory in Linux

After renaming a user it may make sense to change their home directory, too. Otherwise, it would cause a lot of confusion trying to explain why johndoe ‘s home directory is /home/student .

Читайте также:  Pixie dust kali linux установка

To change the user’s home directory we once again use the usermod command. However, this time we need to perform to actions: change the home directory to a new path, and move the contents from the old path into the new path.

We set the new home directory path using the -d or —home flag with the path to the new directory. We must also use the -m flag to copy the contents of the old home directory into the new one.

sudo usermod -d /home/joedoe -m johndoe 

Every user on a Linux system is created with a group of the same name. When we change the name of a user their group name is left untouched. It’s a good idea to also change the user’s primary group name as well.

To change a user’s primary group name we use the groupmod command with the -n flag. We must supply the old name and a new name.

For example, to rename the newly renamed user johndoe ‘s primary group to johndoe from student1 , we would run the following command.

sudo groupmod -n johndoe student1

Changing a User’s UID

A little more rare than renaming a user or changing their home directory is changing their UID. A User’s UID is their unique ID on a Linux system. When we assign permissions to file and directories, we use their UID. Processes started by a user are also executed using a user’s UID.

To change a user’s ID we use the usermod command with the -u flag, followed by a new, unique integer.

For example, to set johndoes UID to 5001, we would run the following usermod command.

sudo usermod -u 5001 johndoe

Источник

Is it possible to rename a Unix user account?

I installed Ubuntu on a computer that is now used by somebody else. I renamed the account with her name, but it only changes the fullname, not the user name, which is still displayed in the top right (in the fast-user-switch-applet ). Is there a command to rename an Unix user account? I’ve thought of creating a new user account with the new name, and then copying everything in the «old» home to the home of the new account. Would it be enough? But then I think the files would have the old account’s permissions’ owner? So should I do chown -R newuser ~ ? Is there a simpler/recommended way to do this?

Читайте также:  Язык клавиатуры linux mint

4 Answers 4

usermod —move-home —login —home

The —move-home option moves the old home directory’s contents to the new one given by the —home option which is created if it doesn’t already exist.

If you want the primary user group to match the new-login-name , add —gid to the command above, but the group must be pre-existing.

See the man page for more info:

Thanks! I didn’t know about this command. 🙂 However, that’s the only account on this computer and the man says this: « You must make certain that the named user is not executing any processes when this command is being executed if the users numerical user ID, the users name, or the users home directory is being changed. usermod checks this on Linux, but only check if the user is logged in according to utmp on other architectures. » Would you suggest using a live cd to do this or creating a temp account that I will delete once it’s done?

Since you’re using Ubuntu and can’t login as root, I would create another account called, say, admin that you use for just this type of task. A temporary account will work just as well but you might as well keep it since you could be doing similar things in the future.

Be aware that usermod —home must contain the full path, e.g. /home/user.name – otherwise the new home directory will be created inside the current working directory.

While it’s possible to rename a user, and usermod will do some of the job, this is quite likely to cause trouble. Here’s a list of places where the user name may appear; I do not claim that this list is exhaustive.

  • The user entry in /etc/passwd and related files (e.g. /etc/shadow , /etc/master.passwd ).
  • Group entries in /etc/group (and /etc/gshadow ).
  • Possibly entries in /etc/sudoers .
  • The system mailbox, typically /var/mail/$USER or /var/spool/mail/$USER .
  • The crontab, typically /var/spool/cron/crontabs/$USER
  • In at jobs ( /var/spool/cron/atjobs/* )

The home directory is likely to appear in even more places. Many applications write absolute paths in various dot files. If you decide to rename the home directory as well (while there’s no requirement that user alice ‘s home directory be /home/alice , having it be /home/bob would be confusing), you’ll need to take care of those. A global replacement will work for most applications, but I make no promises. If possible, keep the old home directory name as a symbolic link to the renamed directory.

Источник

Оцените статью
Adblock
detector