nkunicki
Posts: 3
Joined: Sun Jul 22, 2012 6:48 pm

Change Username

Mon Jul 23, 2012 9:24 pm

Hi,

Can someone lend a hand to me with changing the username from "pi"? :)

I tried the usermod command, but I get an error along the lines of "user pi is currently used by process 1489". Looking at this process it's bash, so I'm guessing my terminal session itself. This happens over both SSH and HDMI.

I then tried useradd to create a whole new user, but I'm not sure this is what I want. The prompt doesn't have anything but the standard $, and there's no colors denoting anything on the filesystem.

I'm sure there's an easy answer to this but I can't figure it out. Any help? :)

Thanks

kobzar
Posts: 37
Joined: Tue Jul 17, 2012 1:09 pm
Location: Ukraine

Re: Change Username

Tue Jul 24, 2012 5:48 am

dont need reneme. Just create new user and copy all files of you need.
This is true way !

http://www.cyberciti.biz/faq/howto-linu ... r-command/
No Fate!

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia

Re: Change Username

Tue Jul 24, 2012 5:58 am

reboot the Pi, don't login to it, ssh to pi using the root user, and then use usermod to change the username.

Otherwise, new user and copy everything over.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

timothy3592
Posts: 64
Joined: Wed Jun 13, 2012 6:06 am

Re: Change Username

Tue Jul 24, 2012 6:25 am

I learned all about how linux keeps track of passwords when I tried out the squeeze image and found out about the "User is required to immediately change their password (root enforced)" message that adding a new user brings up. I was thinking "What IS this?!? I AM root, and I DON'T want this!!!" so after reading just about every manpage on user authentication (even going so far as find / -type f -exec grep "User is required to immediately change their password" '{}' \; ... :D ).

Suffice it to say I now change the default username of pi before I even insert the sd card into the pi.

the important files are these
/etc/passwd
/etc/group
/etc/shadow
/etc/gshadow

about these files
all of these files basically consist of individual entries, one per line, and each entry consists of several colon delimited fields. so for example, in /etc/passwd, which contains a list of users on the system, you will find the following line.
pi:x:1000:1000:,,,:/home/pi:/bin/bash
their are 7 fields here: username : (x here means user has encrypted password) : uid : gid : home dir : shell
users are added to groups by placing a comma separated list of users in a group as the last field on that groups line like so.
pi:x:1001:pi,user2,user3,etc...
here again the x denotes the presence of shadow passwords (eg the gshadow file contains secure group information).
I could go into detail about shadow passwords but thats not needed to change a username.
Since all you need to do is change the word pi to something else in all these files the following will suffice to change your username. the following script will do it (actually I was musing about this for a while and considering releasing my own batch of scripts to customize fresh images akin to raspi-config).

Code: Select all

#/bin/bash
[ $UID = 0 ] || exit 1 
#if were here we are root, usually, but be root anyway

echo "you are about to regex things, this is generally considered heavy handed and you are advised to take caution. ctrl-c now to quit without doing anything, otherwise press enter to continue."

#pause the script
line

#ok, the real work
read -p 'Enter Username: ' NEWNAME

#rough test to ensure uniqueness
grep $NEWNAME /etc/passwd
[ $? = 1 ] && exit 1

#back the files up to the fat partition so you can copy them over to a flash stick or something and put them back
cp -t /boot /etc/passwd /etc/group /etc/shadow /etc/gshadow

#do the change
for i in {passwd, shadow, group, gshadow, sudoers}; do
sed -i s/pi/$NEWNAME/g /etc/$i
done

#freshen the backups
for i in {passwd, group, shadow, gshadow}; do cp /etc/$i /etc/$i-; done

#I think were done, normally I do the changes by hand in nano and use regexes very sparingly
#it is possible to back up these file first before doing this by copying them to another directory as root
#so if your careful you can use this blunt instrument of a script
#oh, and I added sudoers up their because otherwise your new username wouldn't have root access via the sudo command
This is the first edition of this tool, I practically wrote it just now, so, feel free to ask a friend or if you have a better idea, then please modify this script as you please.

timothy3592
Posts: 64
Joined: Wed Jun 13, 2012 6:06 am

Re: Change Username

Tue Jul 24, 2012 6:33 am

their are 7 fields here: username : (x here means user has encrypted password) : uid : gid : home dir : shell
oops, I listed 6 should be
username : x : uid : gid : comma separated list full name and other tidbits : homedir : shell

kobzar
Posts: 37
Joined: Tue Jul 17, 2012 1:09 pm
Location: Ukraine

Re: Change Username

Tue Jul 24, 2012 7:19 am

rename usernamr is no true Way !!!!
No Fate!

User avatar
RaTTuS
Posts: 10823
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Change Username

Tue Jul 24, 2012 7:40 am

sudo adduser name
then edit /etc/group
add add new user to sudo list [comma seperated
login as new user
ssh-keygen -t rsa

job done

no need to rename anything
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

timothy3592
Posts: 64
Joined: Wed Jun 13, 2012 6:06 am

Re: Change Username

Tue Jul 24, 2012 7:44 am

"No true way?" This is the Raspberry Pi forum, Where there's a will there's a way, and when their isn't a way, we make one.

User avatar
RaTTuS
Posts: 10823
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Change Username

Tue Jul 24, 2012 8:06 am

there are many way to skin a cat,
and in linux there even more ....
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

kobzar
Posts: 37
Joined: Tue Jul 17, 2012 1:09 pm
Location: Ukraine

Re: Change Username

Tue Jul 24, 2012 8:08 am

timothy3592 wrote:"No true way?" This is the Raspberry Pi forum, Where there's a will there's a way, and when their isn't a way, we make one.
RPI and Linux user its no one !
Linux- is linux.
No Fate!

timothy3592
Posts: 64
Joined: Wed Jun 13, 2012 6:06 am

Re: Change Username

Tue Jul 24, 2012 8:34 am

kobzar, dude, were up to like 3 different solutions here, and your up to like 3 posts saying stuff like "you can't do that" and I can't help feeling that what you really mean is "you shouldn't even try that". Wait!... could you be?... raspberrypi's first forum troll?... ease up, its a try new things even if it just for the fun of it party and everybody's invited.


Image
Troll on bro!

kobzar
Posts: 37
Joined: Tue Jul 17, 2012 1:09 pm
Location: Ukraine

Re: Change Username

Tue Jul 24, 2012 8:38 am

i am just try help!
This is no linux power user forum. I think after rename topic starter have e some error later.
Thats why i dont recomended rename user...
This is no true way to new linux users only...
No Fate!

timothy3592
Posts: 64
Joined: Wed Jun 13, 2012 6:06 am

Re: Change Username

Tue Jul 24, 2012 8:56 am

I was considering not sidetracking this thread further. But I might have actually misjudged your intent. Your not a troll after all. Language is one hell of a barrier isn't it. You'd be surprised though, just now I saw a thread in french, and people answered in french. I'd say we have one hell of a community here. :mrgreen:

kobzar
Posts: 37
Joined: Tue Jul 17, 2012 1:09 pm
Location: Ukraine

Re: Change Username

Tue Jul 24, 2012 9:36 am

timothy3592 wrote:I was considering not sidetracking this thread further. But I might have actually misjudged your intent. Your not a troll after all. Language is one hell of a barrier isn't it. You'd be surprised though, just now I saw a thread in french, and people answered in french. I'd say we have one hell of a community here. :mrgreen:
Sorry for my english please. I am better in future !
No Fate!

nkunicki
Posts: 3
Joined: Sun Jul 22, 2012 6:48 pm

Re: Change Username

Tue Jul 24, 2012 10:23 am

Thanks for the replies. :)

I guess one of the issues I'm having is when I useradd, the user seems to have no preferences. Their shell is black and white, not green and blue like the default pi user. My Googling shows this is held in ~/.bashrc, but copying this to the new users home directory does nothing? Is there anything else I need to do?

I think once I've figured that out, I won't bother renaming the user, rather I'll add a new user and delete the old one.

Cheers!

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2876
Joined: Sat Mar 03, 2012 11:57 am
Location: UK

Re: Change Username

Tue Jul 24, 2012 3:17 pm

Most of the suggestions have it covered already, but a couple of weeks ago I wrote a short blog post about how to get round the OP's problem...

http://raspi.tv/2012/how-to-create-a-ne ... spberry-pi

In the absence of a root user (although root is present on the new Raspbian release) I suggested creating a new user and giving it the same sudo privileges as pi, then deleting pi. Have a look if you're interested. :D
Alex Eames RasPi.TV, RasP.iO

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Change Username

Tue Jul 24, 2012 4:04 pm

I do think that kbozer (or whatever) is a troll, but that's just me.

Anyway, the simplest and best way to do this is just to "vi" the passwd and shadow and groups and sudoers files and change (edit) the username. It is important to realize that in Unix, the "username" is really just "show" - with a small number of exceptions (most of which are obvious and which can be counted on the fingers of one hand, what matters is the numeric userid. The point is that as long as you don't change the userid (number), everything will "just work".

I've always found that when I go the "make a new user and try to make it just like the old one" route, I spend days (or weeks) going around and adding this and adding that, and so on and so on.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2876
Joined: Sat Mar 03, 2012 11:57 am
Location: UK

Re: Change Username

Tue Jul 24, 2012 6:09 pm

Joe Schmoe wrote:I've always found that when I go the "make a new user and try to make it just like the old one" route, I spend days (or weeks) going around and adding this and adding that, and so on and so on.
I'm sure you're right about that Joe. I shouldn't think it matters much with a fairly fresh image of the OS, but if you've spent weeks or more crafting the perfect system...
Alex Eames RasPi.TV, RasP.iO

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Change Username

Tue Jul 24, 2012 7:29 pm

Indeed.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

happyharrysco1
Posts: 8
Joined: Sun Dec 16, 2012 1:37 am

Re: Change Username

Sun Jan 27, 2013 9:08 pm

the easiest way to change the pi account name imo is to use the root account, to do that firstly we need to create a password for the root account so you can log in as root, so use

Code: Select all

sudo passwd
then enter the password, and confirm it. after that log out of the pi account and log back in as root. then as root use usermod like so to change the pi account name

Code: Select all

usermod -m -d /home/newusername -l newusername pi
the usermod switches are
-m move the contents of the existing home dir to the new one created by -d
-d create the new home dir
-l change the account name to this
pi - the account to make these changes too
obviously you replace newusername with the name you want to use on the account, so if you were changing the pi account to eben you would do

Code: Select all

usermod -m -d /home/eben -l eben pi
then edit the sudoers file using visudo to represent your new username

Code: Select all

visudo
then use the down arrow to find the following line

Code: Select all

pi   ALL=(ALL)   NOPASSWD:  ALL
and replace 'pi' with your new username, so it will read

Code: Select all

newusername   ALL=(ALL)   NOPASSWD:  ALL
again if we were changing the pi account name to eben it would read,

Code: Select all

eben   ALL=(ALL)   NOPASSWD:  ALL
once the changes are made press ctrl + o to save the sudoers file, then press ctrl + x to exit visudo.

once that is done log out of the root account and log back in as your new user, now to disable the root account password again use

Code: Select all

sudo passwd -d -l root
and you are done :)

efflandt
Posts: 359
Joined: Mon Dec 03, 2012 2:47 am
Location: Elgin, IL USA

Re: Change Username

Thu Jan 31, 2013 8:20 am

Read man adduser

adduser does more than low level useradd, which is why you did not have the usual prompt you would have had with adduser.

User avatar
dudeman
Posts: 22
Joined: Sun Jan 20, 2013 1:20 am
Location: USA

Re: Change Username

Fri Feb 01, 2013 6:26 pm

the easiest way to change the pi account name imo is to use the root account, to do that firstly we need to create a password for the root account so you can log in as root
Just to clarify, I am sure the author here means log into a shell as root, not into xwindows!

CTRL-ALT-F3 or F4 etc. is a good way to get a virtual terminal shell prompt and log in as root. Type exit when you are through. CTRL-ALT-F7 to get back to xwindows.

johnsmithdoe14
Posts: 1
Joined: Wed Dec 26, 2012 8:23 pm

Re: Change Username

Tue Feb 12, 2013 2:54 pm

yes thats right, but you need to log out of the 'pi' user account to make these changes, so switching out to another terminal before logging out of the account you are renaming will not suffice so please make sure and do this

aronczegledi98
Posts: 2
Joined: Sun Jan 12, 2014 8:57 am
Location: Pomáz, Hungary

Re: Change Username

Sat Mar 15, 2014 8:02 pm

Hi!

I made a video about changing your username on a Raspberry Pi.
Thank you for watching.
https://www.youtube.com/watch?v=jeYEtu8hO-I
<(^-^)> 4RC2 = 4Ron attila C2egledi

Return to “Beginners”