WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Changing the default user from tc in picore  (Read 5087 times)

Offline Joe_H

  • Newbie
  • *
  • Posts: 16
Changing the default user from tc in picore
« on: March 10, 2020, 12:09:05 PM »
Hi,

I was wondering if someone could explain hwo to successfully change the default user 'tc' in picore. I have read 'Into the Core' (twice) and have also looked on this forum and on the wiki on this issue and cannot get a proper explanation of how to do it successfully.

I am running my RPi0W headless and remotely so I have already messed it up once by trying to change the user and it woudl not boot properly then and wouldn't register on the lan. I had to get my wife to remove the SD card and remove the bootcode 'user=xyz' from cmdline.txt.

Clearly, something other than the bootcode is required to successfully change the default user. I have noticed that in the file /etc/init.d/tc-config it has the line early in it USER='tc'. Is this a hardcoding of the username or does this populate from the bootcode?

I'd be interested in hearing from anyone on how they successfully changed the default user in terms of what else they had to change other than the bootcode. Many thanks.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Changing the default user from tc in picore
« Reply #1 on: March 10, 2020, 12:32:48 PM »
Hi Joe_H
... I have noticed that in the file /etc/init.d/tc-config it has the line early in it USER='tc'. Is this a hardcoding of the username or does this populate from the bootcode? ...

Then further down in  /etc/init.d/tc-config  the  user=  boot code is read:
Code: [Select]
user*) USER=${i#*=} ;;
Yet further down it gets acted on:
Code: [Select]
if [ -n "$USER" ]; then
if ! grep "$USER" /etc/passwd >/dev/null; then addUser; fi
else
USER="tc"
fi
echo "$USER" > /etc/sysconfig/tcuser
mkdir -p /home/"$USER"
So the boot code  user=xyz  should create a new user (if that user does not already exist) and make that the default user.

Offline Joe_H

  • Newbie
  • *
  • Posts: 16
Re: Changing the default user from tc in picore
« Reply #2 on: March 10, 2020, 01:07:54 PM »
Rich

Thanks - yes that is clear so it isn't a hardcoding issue in that file so. I successfully changed the computer name from box using the relevant bootcode but the user bootcode is causing the RPi0 to not log into the wireless lan. Do you know why this is? As far as I can recall the user doesn't come into the wifi registration. I have it setup currently as a dhcp client (default) but will change it to a static ip as I will use port forwarding. I want to change the default username as it will be open on internet for SSH (not port 22) and I want the additional security of a different username that a hacker would have to guess as well as the password.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Changing the default user from tc in picore
« Reply #3 on: March 10, 2020, 01:29:43 PM »
Hi Joe_H
... but the user bootcode is causing the RPi0 to not log into the wireless lan. Do you know why this is? As far as I can recall the user doesn't come into the wifi registration. ...
I doubt the contents of the  /home/tc  user are copied to the new users directory when the new user is created, So if you used
wifi.tcz  for example to set up your wireless connection while logged in as user  tc,  you probably need to copy over some files.

Quote
I want to change the default username as it will be open on internet for SSH (not port 22) and I want the additional security of a different username that a hacker would have to guess as well as the password.
It's nice to see some people understand that your user name is effectively the other half of your password, and shouldn't be
advertised if it can be avoided.

Offline Joe_H

  • Newbie
  • *
  • Posts: 16
Re: Changing the default user from tc in picore
« Reply #4 on: March 10, 2020, 02:08:03 PM »
Rich

Thanks - I think you're right. I had assumed that the tc /home went to the new user but it seems it doesn't. The access to the wifi is in tc's home folder (wifi.db) so that is probably why it isn't logging into the network. I'll redo the whole installation of the system but with the new user rather than tc and that should hopefully solve the problem as that is the neatest solution. I'll report back on that when I do it but it won't be until next week as I'm travelling abroad this week.

Joe

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Changing the default user from tc in picore
« Reply #5 on: March 10, 2020, 02:18:08 PM »
Hi Joe_H
You might be able to just do a mass copy:
Code: [Select]
busybox cp -a /home/tc/* /home/NewUserName/

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11041
Re: Changing the default user from tc in picore
« Reply #6 on: March 10, 2020, 02:19:06 PM »
No need to redo everything, you can just edit your backup tarball (as root, unpack, move the home dir, pack). This needs to be done as root so that permissions and ownership are kept.
The only barriers that can stop you are the ones you create yourself.

Offline Joe_H

  • Newbie
  • *
  • Posts: 16
Re: Changing the default user from tc in picore
« Reply #7 on: March 11, 2020, 12:04:44 PM »
Thanks Rich & Curaga - I may try just changing the backup file as you suggest but I notice that a number of other files outside of /home refer to the tc user such as cron and others. It may be safer for me to ensure that tc definitely isn't a user in the system with the default password by setting the user= bootcode before I do the very first installation of the system. As I am doing a complete headless install on a RPi0W I need to do a certain amount of manipulation before the SD card goes into the pi for the first time as I need to install wireless drivers etc. and editing the bootcodes is easy at that point. I first boot the pi with a USB-ethernet adaptor and ssh into it and setup the wireless and avoid having to connect any monitor or keyboard to it at all.

Offline Joe_H

  • Newbie
  • *
  • Posts: 16
Re: Changing the default user from tc in picore
« Reply #8 on: March 17, 2020, 03:13:24 PM »
Ok - I'm still no closer to changing the default user on the system. I have a completely new install on an SD card (picore 9.0.3) and I changed the host= and user= options and ran it in a RPi3 that is connected to the lan. I tried it with the usb-lan adaptor I have but it wouldn't register on the network. I don't have a mini-HDMI (why did they not choose a micro-HDMI??) so had to run instead in a RPi3 to see what was going on. If the user= boot code is used it doesn't automatically load into the user and instead is asking for a password. When I removed that bootcode it did load immediately into tc user. I also wasn't able to ssh into the device either with the new user (note that this is on a completely fresh image on SD card). I connected a keyboard to the RPi3 and rebooted it and entered the password piCore but it was saying it is incorrect. What is it? tc is setup for autologin but why not this new user?

My question is simply has anyone ever actually succeeded in changing the default user from tc and how EXACTLY did they do it?

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Changing the default user from tc in picore
« Reply #9 on: March 17, 2020, 04:24:25 PM »
Hi Joe_H
The tc-config has an  addUser  function that looks like this:
Code: [Select]
addUser(){
echo "${GREEN}Adding user ${YELLOW}$USER ${NORMAL}"
/usr/sbin/adduser -s /bin/sh -G staff -D "$USER"
echo "$USER":tcuser | /usr/sbin/chpasswd -m
echo -e "$USER\tALL=NOPASSWD: ALL" >> /etc/sudoers
}
If you use the  user=  boot code it should create that user with no password required as well as a home directory for that user.
Do this using a keyboard and monitor. Once booted, you should be in the new users home directory. Set up  your wifi. If you don't
have a persistent  /home, make sure it's included in your backup.

Quote
entered the password piCore but it was saying it is incorrect. What is it?
Maybe it's carriage return?
The password is  tcuser

    [EDIT]: Added strikeouts and the password.
« Last Edit: December 30, 2020, 10:15:18 AM by Rich »

Offline Joe_H

  • Newbie
  • *
  • Posts: 16
Re: Changing the default user from tc in picore
« Reply #10 on: March 17, 2020, 04:35:12 PM »
Rich - thanks but couldn't figure out what the password was. I'm going to use a workaround as the user= bootcode isn't working as I thought it would and is too complicated (for me) to figure out what else needs to change in order for it to work correctly. I will leave that bootcode out and instead create a new user with the user name I want and all the permissions of tc. In sshd_config I will block tc from sshing with DenyUsers tc line added to it. I've tried it out and it works fine.