Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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. 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.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.