Login Behavior in Ubuntu

Hi

I believe on later version past Ubuntu 20.04, executing
incus exec $INSTANCE_NAME -- sudo -i -u $INSTANCE_USER , it will create pty on login, which I tried to disable on sudoers with 'Defaults !use_pty`, it didn’t work.

$  systemctl status
● ubuntu02
    State: running
    Units: 286 loaded (incl. loaded aliases)
     Jobs: 0 queued
   Failed: 0 units
    Since: Thu 2024-04-11 05:19:43 UTC; 35min ago
  systemd: 255.4-1ubuntu7
   CGroup: /
           ├─.lxc
           │ ├─37 sudo -i -u ubuntu
           │ └─38 -bash
           ├─init.scope
           │ └─1 /sbin/init
           ├─system.slice
           │ ├─console-getty.service
           │ │ └─310 /sbin/agetty -o "-p -- \\u" --noclear --keep-baud - 115200,38400,9600 linux
           │ ├─cron.service
           │ │ └─142 /usr/sbin/cron -f -P
           │ ├─dbus.service
           │ │ └─143 @dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
           │ ├─networkd-dispatcher.service
           │ │ └─146 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
           │ ├─rsyslog.service
           │ │ └─154 /usr/sbin/rsyslogd -n -iNONE
           │ ├─systemd-journald.service
           │ │ └─77 /usr/lib/systemd/systemd-journald
           │ ├─systemd-logind.service
           │ │ └─141 /usr/lib/systemd/systemd-logind
           │ ├─systemd-networkd.service
           │ │ └─129 /usr/lib/systemd/systemd-networkd
           │ ├─systemd-resolved.service
           │ │ └─131 /usr/lib/systemd/systemd-resolved
           │ └─systemd-udevd.service
           │   └─udev
           │     └─119 /usr/lib/systemd/systemd-udevd
           └─user.slice
             └─user-1000.slice
               ├─session-c1.scope
               │ └─211 ssh-agent -a /tmp/.../ssh.sock
               ├─session-c4.scope
               │ ├─312 sudo -i -u ubuntu
               │ └─313 -bash
               ├─session-c5.scope
               │ ├─456 sudo -i -u ubuntu
               │ ├─457 -bash
               │ ├─488 systemctl status
               │ └─489 pager
               └─user@1000.service
                 └─init.scope
                   ├─180 /usr/lib/systemd/systemd --user
                   └─181 "(sd-pam)"

On Archlinux and Ubuntu 20.04

$  systemctl status 
● archl
    State: running
    Units: 216 loaded (incl. loaded aliases)
     Jobs: 0 queued
   Failed: 0 units
    Since: Wed 2024-04-10 18:12:15 UTC; 11h ago
  systemd: 255.4-2-arch
   CGroup: /
           ├─.lxc
           │ ├─654 sudo -i -u user
           │ ├─656 sudo -i -u user
           │ ├─657 -bash
           │ ├─886 sudo -i -u user
           │ ├─888 sudo -i -u user
           │ ├─889 -bash
           │ ├─894 systemctl status
           │ └─895 less
           ├─init.scope
           │ └─1 /sbin/init
           └─system.slice
             ├─console-getty.service
             │ └─172 /sbin/agetty -o "-p -- \\u" --noclear --keep-baud - 115200,38400,9600 linux
             ├─dbus-broker.service
             │ ├─165 /usr/bin/dbus-broker-launch --scope system --audit
             │ └─166 dbus-broker --log 4 --controller 9 --machine-id <id> --max-bytes 536870912 --max-fds 4096 --max-matches 16384 --audit
             ├─systemd-homed.service
             │ └─167 /usr/lib/systemd/systemd-homed
             ├─systemd-journald.service
             │ └─105 /usr/lib/systemd/systemd-journald
             ├─systemd-logind.service
             │ └─168 /usr/lib/systemd/systemd-logind
             ├─systemd-networkd.service
             │ └─151 /usr/lib/systemd/systemd-networkd
             ├─systemd-resolved.service
             │ └─154 /usr/lib/systemd/systemd-resolved
             ├─systemd-udevd.service
             │ └─udev
             │   └─143 /usr/lib/systemd/systemd-udevd
             └─systemd-userdbd.service
               ├─113 /usr/lib/systemd/systemd-userdbd
               ├─883 systemd-userwork
               ├─884 systemd-userwork
               └─885 systemd-userwork

Any idea how can I allow sudo login to be handled by “.lxc” cgroup for Ubuntu 22.04 or 24.04?
File ‘/etc/systemd/system-generators/lxc’ is present on 24.04 container downloaded from incus image server (fingerprint: 1156f44e8df4)

Thanks!

Alright, solved the issue by executing these two commands:
sudo systemctl stop systemd-logind.service; sudo systemctl mask systemd-logind.service

After which, open another terminal tab and execute incus exec $INSTANCE_NAME -- sudo -i -u $INSTANCE_USER, this login will not be shown on w command.

1 Like