LillysTittchen
Posts: 10
Joined: Fri Aug 07, 2020 11:51 pm

Chnage initial user before first boot

Fri Aug 07, 2020 11:57 pm

Hi,
I'm going to set up my raspberry pi and I was wondering if I can change the initial/default user pi. After using the Pi Imager to write the partitions I have a visible fat partiton "boot" and another partition which I can't inspect because I'm on a Windows 10 PC. I doubt that the information for the initial user are store on the boot partition so is there any script or something which creates the initial user pi on first boot or more generally does someone know how this user is created under the hood?

Thanks in advance!

pidd
Posts: 3912
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: Chnage initial user before first boot

Sat Aug 08, 2020 12:37 am

You probably could edit the configuration with a linux computer but I really wouldn't recommend it. Get the Pi up and running before you start going off the beaten track. Its easy to make other users once you have the system up and running.

LillysTittchen
Posts: 10
Joined: Fri Aug 07, 2020 11:51 pm

Re: Chnage initial user before first boot

Sat Aug 08, 2020 2:52 am

I solved it by myself:

You can control the initial user via cloud-init. If one has access to the other partiton (other than boot) you can edit the /etc/cloud/cloud.cfg. It's the distro config of cloud-init. At the bottom, just edit:

Code: Select all

   default_user:
     name: ubuntu
If you have no access to this partiton because you are a Windows user like me you can use the user-data configuration file for cloud-init. At this point I'm not talking about the pi image anymore but rather the ubuntu server for pi image. This has a file called user-data on the system-boot partition (pendant to pi's boot partition). Edit this file with a text editor and insert the following:

Code: Select all

#cloud-config

# This is the user-data configuration file for cloud-init. By default this sets
# up an initial user called "ubuntu" with password "ubuntu", which must be
# changed at first login. However, many additional actions can be initiated on
# first boot from this file. The cloud-init documentation has more details:
#
# https://cloudinit.readthedocs.io/

# On first boot, set the (default) ubuntu user's password to "ubuntu" and
# expire user passwords
chpasswd:
  expire: true
  list:
  - pi:pi

# Enable password authentication with the SSH daemon
ssh_pwauth: true

#users:
#- name: robot
#  gecos: Mr. Robot
#  groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
#  lock_passwd: false
#  plain_text_passwd: 'ubuntu'

system_info:
  default_user:
    name: pi
    lock_passwd: True
    gecos: Pi
    groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
You can now login with pi and pw is also pi. After first login you will be asked to change the pw. I noticed this file is missing on the boot partition of the pi image so I'm not sure if you can create this file and it will be applied.

User avatar
davidcoton
Posts: 6820
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Chnage initial user before first boot

Sat Aug 08, 2020 9:02 am

ubuntu
If you need to ask for help here, it really is important to disclose relevant facts like which OS you are using in your first post.
Location: 345th cell on the right of the 210th row of L2 cache

User avatar
DougieLawson
Posts: 42232
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Change initial user before first boot

Sat Aug 08, 2020 9:43 am

davidcoton wrote:
Sat Aug 08, 2020 9:02 am
ubuntu
If you need to ask for help here, it really is important to disclose relevant facts like which OS you are using in your first post.
Also for questions like this that are deep in the bowels of Ubuntu it would be better to post on https://ubuntuforums.org/
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

GlowInTheDark
Posts: 2331
Joined: Sat Nov 09, 2019 12:14 pm

Re: Chnage initial user before first boot

Sat Aug 08, 2020 9:59 am

davidcoton wrote:
Sat Aug 08, 2020 9:02 am
ubuntu
If you need to ask for help here, it really is important to disclose relevant facts like which OS you are using in your first post.
This post is currently in the "Ubuntu" forum. Doesn't that tell you something?

(Note that it is possible that it was originally posted to General or something like that and subsequently moved. I cannot determine that with the information currently available to me.)
Poster of inconvenient truths.

Back from a short, unplanned vacation. Did you miss me?

User avatar
PeterO
Posts: 6095
Joined: Sun Jul 22, 2012 4:14 pm

Re: Chnage initial user before first boot

Sat Aug 08, 2020 10:16 am

GlowInTheDark wrote:
Sat Aug 08, 2020 9:59 am
This post is currently in the "Ubuntu" forum. Doesn't that tell you something?
It tells me that it has been moved here from "Advanced Users" where it was originally.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Ubuntu”