Useradd working differently between versions

I am running lxd on snap on debian stable with most of my container images being various variants of debian (stable, testing and sid) although I have one image of ubuntu:trusty.

I have been trying to get x2go working on some containers that I setup after I upgraded from lxd 2.xx to lxd 3.0. I have noticed some interesting behavior with differences between containers developed before the upgrade to lxd 3.0 and those developed after.

Containers developed before the upgrade to lxd 3.0 where a userID had been added AND x2go had been setup I am able to access the container remotely using x2go and am able to log into the user using # su userID and the prompt then reads $ userID. In the containers developed AFTER upgrading to lxd 3.0, on the other hand, not only am I not able to use x2go but when I log into the user using #su userID the prompt then reads $ (goofy system won’t let me create a blank space here!!!) (note that there is no userID). To make things even more interesting I had one container setup to use ubuntu trusty (I would like to test something where it was setup to run on ubuntu trusty and has never since been upgraded). This container was set up using lxd 2.xx without any added users. I started the container to check things and used useradd to add a userID. Then I stopped that container and copied it into a new version (using lxd 3.0) and started that. When I log into that container using # su userID - - - well the prompt is $ userID.

Somehow there is a difference between debian based containers and ubuntu based containers in lxd3.0.
How do I achieve this different ‘login’ prompt (if that is the issue) or what needs to be changed (or is this a bug)?

Hi!

I expect some differences between Debian and Ubuntu. For what you are trying to describe, I think it would be important to demonstrate the issue in an easy-to-understand way.

Here is an excerpt from some shell comamnds. It is beautiful. How did I do it?
Here is the source, https://pastebin.ubuntu.com/p/QnrQmxTWws/ What I did, is I added special text at the beginning and the end. (in pastebin, they are lines 1 and 14).

$ lxc ubuntu cutter
ubuntu@cutter:~$ pwd
/home/ubuntu
ubuntu@cutter:~$ sudo su -
mesg: ttyname failed: Success
root@cutter:~# su ubuntu
ubuntu@cutter:/root$ exit
exit
root@cutter:~# exit
logout
ubuntu@cutter:~$ exit
logout

It would be great if you could show what you really get in all the cases that you describe, by copying and pasting the commands from your terminal.

OK docs wanted:

  1. previously setup where userID works and x2g0 works
memyself@debianserver:~$ lxc exec deb-recordkeeping bash
root@deb-recordkeeping:~# su memyself
memyself@deb-recordkeeping:/root$ exit
  1. version where ubuntu:trusty is used
    this is where the container was set up quite some time ago with the user being added (useradd) today for testing purposes. userid shows correctly (container setup in lxd 2.xx with useradd done in lxd3.0) but this is an ubuntu container whereas most of mine are not ubuntu based.
memyself@debianserver:~$ lxc exec ubuntu-robotics bash
root@ubuntu-robotics:~# su memyself
memyself@ubuntu-corobotics:/root$ exit
  1. container and userID using lxd2.xx, accessed today using lxd3.0 for testing purposes.
memyself@debianserver:~$ lxc exec deb-horde-server bash
root@deb-horde-server:~# vi /etc/passwd
root@deb-horde-server:~# su memyself
$ exit

I was using vi /etc/passwd to make sure that the user was listed in the correct location.

TIA

$ su --help
Usage: su [options] [LOGIN]

Options:
  -c, --command COMMAND         pass COMMAND to the invoked shell
  -h, --help                    display this help message and exit
  -, -l, --login                make the shell a login shell
  -m, -p,
  --preserve-environment        do not reset environment variables, and
                                keep the same shell
  -s, --shell SHELL             use SHELL instead of the default in passwd

When you use su, it is nice to use the parameter --login in order to get a login shell.
Because

root@deb-recordkeeping:~# su memyself
memyself@deb-recordkeeping:/root$ exit

gets you to become user memyself but keeps you in the current directory, /root, which you probably do not have access.

When you use su and you get just the $ prompt, then that means that the shell has trouble reading the configuration files.
Try again with --login (or the other two shortcuts) and report back.

The $ instead of memyself@... prompt usually indicates that /bin/sh is used as the user’s shell rather than /bin/bash.

To confirm, just run bash after su to the user.

root@deb-recordkeeping:~# su --login
mesg: ttyname failed: No such device
root@deb-recordkeeping:~# su -l memyself
memyself@deb-recordkeeping:~$

ok that works (but it also did that before - - - not seeing an advantage to changing practice yet).

  1. version where ubuntu:trusty is used
    this is where the container was set up quite some time ago with the user being added (useradd) today for testing purposes. userid shows correctly (container setup in lxd 2.xx with useradd done in lxd3.0) but this is an ubuntu container whereas most of mine are not ubuntu based.

(trying some things as well!)

memyself@debianserver:~$ lxc exec ubuntu-robotics /bin/bash
root@ubuntu-robotics:~# su -l memyself
No directory, logging in with HOME=/
$ exit
logout
root@ubuntu-robotics:~# cd /home
root@ubuntu-robotics:/home# ls
ubuntu
root@ubuntu-corobotics:/home# mkdir /home/darald
root@ubuntu-corobotics:/home# cd /
root@ubuntu-corobotics:/# cd ~
root@ubuntu-robotics:~# su -l memyself
$ exit
logout
root@ubuntu-robotics:~# su memyself
memyself@ubuntu-robotics:/root$

in this instance there seems to be no advantage to using su -l userID (in fact the opposite)
interesting is that /home has a directory ‘ubuntu’ - - - no such directory shows up in the other containers where userID has been added

  1. container and userID using lxd2.xx, accessed today using lxd3.0 for testing purposes.

memyself@debianserver:~$ lxc exec deb-horde-server /bin/bash
root@deb-horde-server:~# su -l memyself
No directory, logging in with HOME=/
$ exit
root@deb-horde-server:~# mkdir /home/memyself
root@deb-horde-server:~# ls /home/
memyself
root@deb-horde-server:~# su -l memyself
$ exit
root@deb-horde-server:~# exit
exit
memyself@debianserver:~$ lxc exec deb-horde-server /bin/bash
root@deb-horde-server:~# su -l memyself
$ /bin/bash
memyself@deb-horde-server:~$

OK so it works - - - but it takes more steps AND it doesn’t work with the previous workflow. This means that something has been changed and even though I think I can now get userID logins I still cannot get x2go connections for any of the containers set up using lxd3.0. (Logging out is now a 3 step process instead of a 2 step one as well.)

So I’m back to the original question - - - what’s different. Some characteristics have been changed from lxd 2.xx to lxd3.0 and they are creating problems with what I am trying to do.

Is it possible that lxd can only really be used on ubuntu running snap?

So, how does one create users in a Linux distrubution?

ubuntu@addingusers:~$ sudo useradd useradd
ubuntu@addingusers:~$ sudo adduser adduser
Adding user `adduser' ...
Adding new group `adduser' (1002) ...
Adding new user `adduser' (1002) with group `adduser' ...
Creating home directory `/home/adduser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for adduser
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] 
ubuntu@addingusers:~$

That is, there are two ways. One with useradd, and another with adduser. And they are very different.

The problem you are facing is that it’s error-prone to use useradd, because you have to be careful to add as a parameter all the details of the account. Simply running useradd myaccount with no parameters is insufficient.

Here is how the /etc/passwd file looks for each account:

useradd:x:1001:1001::/home/useradd:
adduser:x:1002:1002:,,,:/home/adduser:/bin/bash

In the case of useradd, the directory /home/useradd was not even created. It does not specify a shell either, meaning that it uses whatever is default for the distribution.

Below we su to an account called useradd that was created with sudo useradd useradd.
It complains that the home directory. You have the same error in your reply, which means that indeed you used useradd for some of your accounts.

ubuntu@addingusers:~$ sudo su - useradd
No directory, logging in with HOME=/
$ 

I suspect that in same cases, you wrote adduser and in others useradd.
You need to go back and fix those useradd accounts and add whatever is missing using the usermod command.

Your instructions are not accurate. It is possible to use sudo in any distribution - - - ubuntu is one that requires its use.

The problem you are facing is that it’s error-prone to use useradd, because you have to be careful to add as >a parameter all the details of the account. Simply running useradd myaccount with no parameters is >insufficient.

What is fascinating is that this is how the users were created on the containers that do do what they’re supposed to (when I was using lxd2.xx) I remember having to add a directory for the user (using mkdir) because it was necessary to use the full path for that directory to be created as with the minimum path the command just didn’t work.

This is really starting to look like one of the small (but increasing in number) ways where ubuntu is different than debian.

Having done all of what you had suggested I still don’t have a way of getting x2go working when it worked quite well when I used it before version lxd3.0 . So I guess it means revert to lxd2.xx or ???

I stand by what I wrote in my previous reply. Please read it carefully.

You do understand that where I did what you have told me I shouldn’t do - - - - things work (when I did them with lxd2.xx).
Now when I do them either way (in lxd3.0) they DON’T work.

So the arguments pro or contra useradd or adduser are mut.