Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Installing MinimServer on Linux using su
01-10-2021, 10:09
Post: #1
Installing MinimServer on Linux using su
I'm installing MinimServer on a Pi running Ubuntu. I've created a MinimServer account and switch to that using "su - minimserver " or "sudo -i -u minimserver" but whenever I run minimserver/bin/setup it places my account name in the /etc/init.d/minimserver script rather than minimserver.

I'm assuming it's falling back on my sudo privileges as during setup it "Acquiring root privilege for system configuration update..." but never asks for the minimserver sudo password (although does fail if it doesn't belong to sudo group).

I know I can get it working by just modifying the script, or logging in directly (I assume), but does anyone know why this happens, and if there's a way of getting it to work through user switching?

I assume it's a Linux thing rather than MinimServer but thought someone might understand what's going on when using su.
Find all posts by this user
Quote this message in a reply
01-10-2021, 20:54
Post: #2
RE: Installing MinimServer on Linux using su
MinimServer uses the output of the logname command as the username to write into the /etc/init.d/minimserver script. If the logname command produces no output, MinimServer uses the value of the $LOGNAME environment variable. If the $LOGNAME variable has no value, MinimServer assumes the username is root.

With your setup, what is the output from the logname command and what is the value of the $LOGNAME variable?
Find all posts by this user
Quote this message in a reply
01-10-2021, 22:19 (This post was last modified: 02-10-2021 09:38 by simbun.)
Post: #3
RE: Installing MinimServer on Linux using su
As per this answer it looks like logname returns the owner of the terminal, whereas $LOGNAME returns the user that executes the current shell.

In my scenario, I logged into the server via putty using account SIMON after which I switched to minimserver (su -i minimserver), and in that shell logname returned SIMON whereas $LOGNAME returned minimserver.

I tend to just use 'id -un' but have no idea how compatiable that is across distributions.
Find all posts by this user
Quote this message in a reply
02-10-2021, 09:38
Post: #4
RE: Installing MinimServer on Linux using su
Having thought about it, you're probably falling back on logname because you're trying to get the UID from within a SUDO call.
I tried to do something like this a while ago and I couldn't find a way to expose the Real UID from the shell as opposed to the Effective UID either, which was maddening.
I fell back on using $SUDO_USER, which should be ok if you're controlling how it's being called (doing the sudo call yourself), but it doesn't work in all scenarios ("sudo su - <another user>" from memory).

Again, no idea how this works across distributions, but it can't hurt if it's just an additional check before logname.
Find all posts by this user
Quote this message in a reply
02-10-2021, 10:27
Post: #5
RE: Installing MinimServer on Linux using su
The setup script doesn't use logname or $LOGNAME when it is running with root privilege (within a sudo call). It uses these when running without root privilege and passes the result to the sudo call.

I have tried doing what you are doing on two different Linux systems and I get the same result as you. I am not sure if there was a reason why the result of the logname command was used in preference to the $LOGNAME value when this code was written. At this point, I think the right thing to do is to reverse the order of these two checks, which would solve the problem you are having. If this causes problems in other environments, we can deal with these as needed.

This change will be in the next release of MinimServer for Linux.
Find all posts by this user
Quote this message in a reply
02-10-2021, 14:27
Post: #6
RE: Installing MinimServer on Linux using su
(02-10-2021 10:27)simoncn Wrote:  I am not sure if there was a reason why the result of the logname command was used in preference to the $LOGNAME value when this code was written.
Given you weren't aware of the difference, maybe you chose logname over $LOGNAME because it's immutable, as it's trivial to change the shell variable.

(02-10-2021 10:27)simoncn Wrote:  At this point, I think the right thing to do is to reverse the order of these two checks, which would solve the problem you are having. If this causes problems in other environments, we can deal with these as needed.
Sounds like a safe and sensible approach given all the platforms you have to target!
Happy to be a beta tester at any point - as I'm sure lots of other users would be.
Find all posts by this user
Quote this message in a reply
02-01-2022, 19:04
Post: #7
RE: Installing MinimServer on Linux using su
This change is available now in MinimServer 2.1.
Find all posts by this user
Quote this message in a reply
03-01-2022, 18:30
Post: #8
RE: Installing MinimServer on Linux using su
Just performed a full uninstall and install onto a Pi 4 running 64 bit Ubuntu and everything works as expected.

Thanks @simoncn
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)