Jump to content

How to change a user name?


banjo
 Share

Recommended Posts

I have created a user account on my Mandy 9.1

and now I am unhappy with the name. Just another

tragic mouse accident!

 

I would like to change the name of the user

to something else.

 

Is it possible to change the name of an existing

user account without mucking up the whole thing.?

Other than renaming the home directory and

correcting /etc/passwd, what else needs to be

done?

 

Can the control panel do this for me? (I am

not sitting at my Linux box right at the moment

or I would look that one up).

 

The only thing wrong with the account is the name,

so I would rather not have to start all over again

creating a new user and deleting the old one.

 

Thanks in advance

Banjo

(_)=='=~

Link to comment
Share on other sites

How about, create a new user with name you like. Then as root, copy over the old user's entire home directory to the new user's home directory and allow overwritng on all files. If you do that in konqueror as root, make sure you select View>Show hidden files so you get everything over to your new user's home. Most of the user's config files are hidden files in his home directory so it's importantant to copy those.

Then test the new user and make sure everything works OK. Once your satisfied, delete the old user.

Link to comment
Share on other sites

Hmm. I hadn't thought of that.

 

I guess that is the fastest way to do it.

 

I would probably use the CLI instead of

Konqueror to do the copy. I come from the

old Unix days of iron men and wooden boats,

so it just feels right to do those operations

with a command.

 

But I am gettin' kinda lazy with all this GUI stuff.

This Linux ain't yer granpa's Unix no siree.

 

Thanks for the hint.

 

Banjo

(_)=='=~

Link to comment
Share on other sites

And just to be sure:

# chown -R newuser /home/newuser

# grep -ril olduser /home/newuser

 

If this last command finds some files, then try and locate where your old user name appears in each file. Correct if needed.

 

SwiftDeath, are you sure the command you give is good enough? I mean, does it behave correctly in presence of links, or other non-regular files?

Me, I'd rather do that:

# (cd /home/olduser && tar cf - .) | (cd /home/newuser && tar xpf -)

And for deleting the user, there is IIRC a command for deleting a user, that takes care of both the home-directory, and the /etc/* files.

 

Yves.

Edited by theYinYeti
Link to comment
Share on other sites

Changing the username is simple enough...

 

just edit in /etc/shadow and /etc/passwd but then you need to change ownership of the old files to the new owner and if the group name was the same as the username /etc/group

 

for the home directory its pretty simple

chown -R newuser:newgroup /home/<newuser>

 

the other part though is finding other stuff scattered about...

you can make a recursive find from / and presume if you dont have access then you dont have any files in the dirctory...using a -uid = (uid)

 

you can use the -exec {chown .... } (Im at work on windows now) to change ownership but in the meantime it doesnt matter, even though the owner is written to the inode when created if it has the same uid it will inherit the correct permissions (this is the advantage over making a new user where this isnt the case unless the uid and gid are the same)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...