LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to change the main user name? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-change-the-main-user-name-4175595687/)

Noobtopro 12-18-2016 09:42 AM

How to change the main user name?
 
So how can I change the main user name? It's still from the computer's old owner and I wanna change it.

hazel 12-18-2016 10:59 AM

You don't say what distro you are using. If it's one with a root login (e.g. Fedora, Debian), log in as root and edit the /etc/passwd file, changing the unwanted user name to your own. If you want to inherit the previous owner's home directory, rename that too and write the new name into the passwd file.

If it's something like Ubuntu, where you can't log in as root, things are a little trickier. You will need to use adduser or useradd to create a new user. Then use visudo to edit the /etc/sudoers file and give yourself the same rights as the original owner had. Mind that you use visudo and not any other editor! It will warn you before you save if you have made a syntax error.

Then test that you can now use the sudo command under your own name. If all is well, use visudo again to remove the line referring to the other name, then edit the corresponding line out of passwd.

Noobtopro 12-18-2016 11:33 AM

Thanks for the reply. I'm actually using linux mint. So I can't just rename the old user but have to make new one right?

hazel 12-18-2016 11:45 AM

Quote:

Originally Posted by Noobtopro (Post 5643604)
Thanks for the reply. I'm actually using linux mint. So I can't just rename the old user but have to make new one right?

That's right. Mint is based on Ubuntu. There's no way to work as root except by using sudo, so you have to ensure that your sudoers file is valid at all times. And that means not deleting or editing the old administrative user until you are 100% sure that the new one can do everything that needs doing.

Noobtopro 12-18-2016 12:38 PM

Ok thanks, I'm too scared to too anything then. It's not even that important, LOL

BW-userx 12-18-2016 01:09 PM

kind of like @hazel said, but if you cannot do the change user name in /etc/passwd which you should still be able to regardless if it is Ubunutututu or not, if you posses sudo rights.

the other one is create a new user, then adding that user to sudo or wheel group which ever that system uses for sudo rights, no need to change sudoers file, if all he that other uses has is basic sudo rights.

Code:

cat /etc/sudoers
to get a look inside of it without having to open it. Remember you have to logout then login again for the changes to take effect on adding groups to a user.

if you want everything in that old /home/user then after you create the new user, you should stil be able to su in Ubuntutu, but that is a guess, it'd save you from having to type sudo for each command.


Code:

mv -vf /home/UnwatedUserName/* /home/NewWantedUserName/
chmod NewWantedUserName:NewWantedUserName /home/NewWantedUserName/ -R
rm -r /home/UnwatedUserName

That will move everything within that old user home directory into yours, then make everything yours, and remove the old user home directory.

If you want to keep some of the hidden files, you have to add the . to your equation to get them as well.
But I'd copy or move them over giving them a different ending extension so you can avoid over writing your original files if any, and you'll be able to then deal with each file on a case by case basis.

Personally I'd would just create a new user then use that method to move everything over.

BW-userx 12-18-2016 01:22 PM

Quote:

Originally Posted by Noobtopro (Post 5643620)
Ok thanks, I'm too scared to too anything then. It's not even that important, LOL

it's good practice.... food for thought. but like @hazel said with that type of distro that denies you root. MAKE sure you have a working sudo member created before you do anything on that system.

Noobtopro 12-18-2016 04:41 PM

Thanks mate. I try to figure it out!

hazel 12-19-2016 02:04 AM

I'd do it in stages, perhaps over a week or so.

1. Create a new user for yourself with a new home directory. Copy over the files you want from the existing home directory; make sure they include .bashrc and .bash_profile. From now on you can log in as the new user for most purposes but you'll still need to log in as the old user for housekeeping.

2. Using sudo visudo (as the old user), uncomment the line in sudoers that gives members of the wheel group full access. Then use the usermod command to add the new user to wheel
Code:

sudo usermod -aG wheel newuser
Alternatively, you can add a line for the new user to sudoers, using the one for the old user as a model.

3. Run as the new user for a couple of weeks, doing updates and so on, and checking that you can do everything you need to.

4. If all is well, delete the old user from passwd and from sudoers.

You are right to be cautious about altering your system. You can screw up badly that way. But if you understand what you are doing and work carefully, you can do almost anything in Linux. You have complete freedom to craft your system any way you want it to work.

If you want to do something as root or using sudo and you're not sure if it is safe, just post what you want to do and the commands you plan to use to do it, and ask if that is OK.

Habitual 12-19-2016 05:37 AM

Since it's "Mint", this may apply, How do I change my username?

BW-userx 12-19-2016 06:11 AM

Quote:

Originally Posted by Habitual (Post 5643814)
Since it's "Mint", this may apply, How do I change my username?

That looks like a piece of cake to me. Should work on any Unix Based system, as it stated. Another way to use usermod: good find @Habitual

on that finial deleting of the temporary user It talks about, one can shorten the commands used by a simple,
Code:

userdel -r useName
to remove its home directory.
instead of what it stated to do, which was.
Quote:

Delete temporary user and folder:

sudo deluser temporary
sudo rm -r /home/temporary
userdel command arguments.
Quote:

userx@voider~\>> userdel
Usage: userdel [options] LOGIN

Options:
-f, --force force removal of files,
even if not owned by user
-h, --help display this help message and exit
-r, --remove remove home directory and mail spool
-R, --root CHROOT_DIR directory to chroot into

hazel 12-19-2016 07:36 AM

It's true that files belong to a UID, not a name. You can change the name in the passwd file without affecting anything else. But the sudoers file uses names, not UIDs. I assume sudo looks up the name in passwd to find the UID and then compares that with the UID of the requesting process. So if the passwd file no longer contains that name, I doubt if sudo would work.

BW-userx 12-19-2016 07:56 AM

Quote:

Originally Posted by hazel (Post 5643854)
It's true that files belong to a UID, not a name. You can change the name in the passwd file without affecting anything else. But the sudoers file uses names, not UIDs. I assume sudo looks up the name in passwd to find the UID and then compares that with the UID of the requesting process. So if the passwd file no longer contains that name, I doubt if sudo would work.

the sudo is attached to a group not a user per sa'
then the user or users are then attached to that group, sudo or wheel so no editing of the suders file is actually needed. Providing that within that file (sudoers) it has already been modified to allow user attached to that group sudo rights.
Unless extenuating circumstances are in play.

sundialsvcs 12-19-2016 08:36 AM

The key thing to remember is that the guts of the system uses a numeric user-id ("uid") and a numeric group-id ("gid").

You can therefore purposely create a new user with the same uid as the old, and a new group with the same gid as the old, ignoring any squawks that Linux may make when it notices the conflict. mv the old home-directory to rename it.

When the former user/group identity is removed, Linux will associate the new names with these IDs.


All times are GMT -5. The time now is 05:09 PM.