LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-18-2016, 09:42 AM   #1
Noobtopro
Member
 
Registered: Mar 2016
Posts: 41

Rep: Reputation: Disabled
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.
 
Old 12-18-2016, 10:59 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,041
Blog Entries: 17

Rep: Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218
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.
 
1 members found this post helpful.
Old 12-18-2016, 11:33 AM   #3
Noobtopro
Member
 
Registered: Mar 2016
Posts: 41

Original Poster
Rep: Reputation: Disabled
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?
 
Old 12-18-2016, 11:45 AM   #4
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,041
Blog Entries: 17

Rep: Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218
Quote:
Originally Posted by Noobtopro View Post
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.
 
1 members found this post helpful.
Old 12-18-2016, 12:38 PM   #5
Noobtopro
Member
 
Registered: Mar 2016
Posts: 41

Original Poster
Rep: Reputation: Disabled
Ok thanks, I'm too scared to too anything then. It's not even that important, LOL
 
Old 12-18-2016, 01:09 PM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.

Last edited by BW-userx; 12-18-2016 at 01:16 PM.
 
1 members found this post helpful.
Old 12-18-2016, 01:22 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Noobtopro View Post
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.
 
1 members found this post helpful.
Old 12-18-2016, 04:41 PM   #8
Noobtopro
Member
 
Registered: Mar 2016
Posts: 41

Original Poster
Rep: Reputation: Disabled
Thanks mate. I try to figure it out!
 
Old 12-19-2016, 02:04 AM   #9
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,041
Blog Entries: 17

Rep: Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218
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.

Last edited by hazel; 12-19-2016 at 02:06 AM.
 
Old 12-19-2016, 05:37 AM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Since it's "Mint", this may apply, How do I change my username?
 
Old 12-19-2016, 06:11 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Habitual View Post
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

Last edited by BW-userx; 12-19-2016 at 06:16 AM.
 
Old 12-19-2016, 07:36 AM   #12
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,041
Blog Entries: 17

Rep: Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218Reputation: 4218
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.
 
Old 12-19-2016, 07:56 AM   #13
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by hazel View Post
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.

Last edited by BW-userx; 12-19-2016 at 08:00 AM.
 
Old 12-19-2016, 08:36 AM   #14
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,357
Blog Entries: 4

Rep: Reputation: 3821Reputation: 3821Reputation: 3821Reputation: 3821Reputation: 3821Reputation: 3821Reputation: 3821Reputation: 3821Reputation: 3821Reputation: 3821Reputation: 3821
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to change mail from backup to main server fiona333 Linux - Newbie 1 11-07-2009 10:10 PM
TVTime works for main user, but not for 2nd user... el amigo* Ubuntu 15 06-30-2007 06:35 AM
Change main output in ALSA Umagarz Linux - General 0 06-03-2007 08:10 AM
How to change main language woopud Slackware 5 06-11-2006 06:49 PM
How To change the main menu icon Mikecore Linux - Newbie 0 12-16-2003 05:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration