The answers above are correct, I just want to give another option that may suits you better.
Assuming:
- A brand new raspberry pi
- You want to change the default username
pi
to mypie
- You want to adapt also the main group from
pi
to mypie
- You want other things to work out like sudo and auto-login
Proceed to:
Step 1: stop user pi
from running before the change.
Step 2: make the user change
- If you see the graphical login prompt, you are good. Do not login. Instead, press ALT+F1 (* if you want to do it via ssh, see the apendix)
- After ALT+F1, you should see a
login
question (and not an autologin).
- Login as
root
with your root password. Now you are alone in the system, and changes to pi
will not be met with usermod: user pi is currently used by process 2104
. Check with ps -u pi
to see an empty list.
- Very carefully, key by key, type
usermod -l mypie pi
. This will change your username, from /etc/passwd
file, but things are not ready yet. Anyway, check with tail /etc/passwd
and see the last line mypie:1000:...
The 1000 is the UID and it is now yours.
- Try
su mypie
just to be sure. Do nothing. Just exit
again to root. It should work. Now you need to adjust the group and a $HOME
folder.
Step 3: make the group change
- Type, again carefully,
groupmod -n mypie pi
. This will change the pi
group name. Check it with tail /etc/group
and you will see the last line the new name associated with GID
1000.
- Just to clarify, type
ls -la /home/pi
and you will see that the pi
HOME now belongs to you, mypie
.
Step 4: lets adopt the new home.
- I see in the answers above the creation of a new folder, copying everything. No need. Lets just use the same.
- First move to
cd /home
to make it easier. Type ls -la
and see pi
, onwer mypie
group mypie
- Type carefully:
mv pi mypie
. You now need to associate this change with your new user.
- Type carefully:
usermod -d /home/mypie mypie
. This will change your home directory. Check it with tail /etc/passwd
and look at the sixth field (separated by :
).
Step 5: some adjusts after the fact.
- Reboot with
reboot
- Login as your new user
mypie
in the graphical interface.
- Open a terminal.
Change your password
- Type
passwd
to change the password of mypie
to something else than raspberry
- Type
sudo su -
and you will be asked your password.
auto-login again if you will (I don't recommend, but well)
- If you want to autologin your new account, edit the file:
$vim etc/lightdm/lightdm.conf
- find the line with
#autologin-user=
, change it to autologin-user=mypie
(no comment #)
- If you want back the ALT+F1 autologin, find and edit the file:
$vim /etc/systemd/system/[email protected]
and change the line
#ExecStart=-/sbin/agetty --autologin mypie --noclear %I $TERM
Make your sudo passwordless again (I don't recommend as well)
- Move yourself (root) to
cd /etc/sudoers.d
- Rename the file
010_pi-nopasswd
to 010_mypie_nopasswd
- Open it
vim 010_mypie_nopasswd
and change the line pi ALL=(ALL) NOPASSWD: ALL
to, obviously mypie ALL=(ALL) NOPASSWD: ALL
. It is read-only, so save it forcing with :x!
While you are into it, change your hostname
- Edit
$vim /etc/hosts
and change 127.0.1.1 raspberry
to something more appropriate like 127.0.1.1 myoven
.
- Edit
$vim /etc/hostname
and let a single line with myoven
.
Done
Step 6: reboot
Appendix - ssh
- You may want to do this via ssh. For this to work, first you need to allow root login.
- Find the file
/etc/ssh/sshd_config
- Comment the line
#PermitRootLogin without-password
- Add the line
PermitRootLogin yes
- Save, exit, restart ssh with
/etc/init.d/ssh restart
- After you have done it, undo this changes as they are too dangerous to let that way.
- Same file, delete
PermitRootLogin yes
line and remove the comment from PermitRootLogin without-password
Note 1: This is a guide, and the content deals with very dangerous commands. Backup first, or be aware that maybe you will need to burn again your image. As I am assuming a brand new raspberry pi, there is not much to backup anyway. But if you adapt it to another situation, be advised.
Note 2: There might be more things to change. As I am new to the Raspberry pi (I got mine 2 days ago), I may find other adjusts I left out and I will edit this answer again.
Note 3: My first attempt was to move pi
user and pi
group to another UID
and GID
(1001) and create a new user for me as 1000
. That didn't quite go as I planned and I needed to burn my SD card again after spending the whole day trying to figure out why the "configure you pi" program would not work anymore. But well, this way here is far easier anyway, so here you go: a new pi with just your username as UID 1000 (and all the good stuff in your home).
Note 4: Be advised, after doing that, the standard configuration tool stops working.
footnote: Thanks for the stackexchange raspberrypi community (as I'm new here also).