LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Change user name (https://www.linuxquestions.org/questions/linux-newbie-8/change-user-name-660536/)

Ashhere 08-05-2008 02:26 AM

Change user name
 
Hi,

Can anyone tell me how to change my user name?
Someone suggested to use the usermod command as:

usermod -l login_name user_name
login_name being the new user name.

But,
usermod : unable to lock password file
is the output.

angel115 08-05-2008 02:34 AM

Do you want to change your user name or your login?

colucix 08-05-2008 02:35 AM

Are you running this command as root? If you're running on Ubuntu you can do
Code:

sudo usermod -l new_name -d /home/new_name -m old_name
on other system you have to do su - and enter the root password when prompted to get root privileges. Also - as shown in my example - you can change the home directory as well, since it is not done automatically. The -d option specifies the new home dir and the -m option is meant to move the content of the old home directory to the new one. See man usermod for future reference.

Mr. C. 08-05-2008 02:38 AM

Personally, I just do:

sudo -s
vipw
mv /home/olduser /home/newuser
# the chown below is only necessary of UID or GID change
chown -R newuser:newgroup /home/newuser

The commands like usermod and useradd, etc. are good for scripts.

Add "sudo" in front of the usermod command if you are not root, or become root with either sudo or su, and then run the command.

You also need to move the users home directory (so add -the -m option to usermod) and you need to change all the file and directory permissions from the old user to the new user.

[ edit: again only need to change UID/GID on files if UID/GID if you change UID/GID in passwd file. ]

Ashhere 08-05-2008 02:48 AM

Thanks
 
Thanks everyone.
I am new to linux and didnt know had to log in as root.

jschiwal 08-05-2008 04:12 AM

Quote:

Originally Posted by Mr. C. (Post 3237102)
Personally, I just do:

sudo -s
vipw
mv /home/olduser /home/newuser
chown -R newuser:newgroup /home/newuser

The commands like usermod and useradd, etc. are good for scripts.

Add "sudo" in front of the usermod command if you are not root, or become root with either sudo or su, and then run the command.

You also need to move the users home directory (so add -the -m option to usermod) and you need to change all the file and directory permissions from the old user to the new user.

If you don't want to use usermod, why not just edit /etc/passwd, changing your username field and the home page field. This would retain the UID which might be in tar backups, or external drives. If you keep your old UID, you don't need to run chown on your home directory.

Mr. C. 08-05-2008 11:05 AM

Yes, you are right of course. I don't know what made me think UID/GID was changing here too.

Ashhere 08-06-2008 07:50 AM

The thing has worsened!!
 
I tried changing the username. But now there is another problem.
When I try to log in,a dialog says:

"User's $HOME/.dmrc file is being ignored. This prevents the default session and language from being saved. Fild should be owned by the user and have 644 permissions. User's $HOME directory must be owned by user and not writable by other users.

and when I hit the OK button, it says:

"Your session only lasted less than 10 seconds. If you have not logged out yourself, this could mean that there is some installation problem or that you may be out of disk space. Try logging in with some of the filesafe sessions to see if you can fix this problem."

I logged in in filesale GNOME but the dialogs appear as such again.
What shall I do?
Should I reinstall ubuntu or what? And if to reinstall it too, how?
and can u explain about 644 permissions too?

junpa 08-06-2008 01:56 PM

Ashhere,

well my first question would be...which method did you use to change the username?

and which user are you trying to log in as? old? new?


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