#1087644 openssh-server: no tty associated with login session

Package:
openssh-server
Source:
openssh-server
Description:
secure shell (SSH) server, for secure access from remote machines
Submitter:
Chris Hofstaedtler
Date:
2025-02-17 17:36:06 UTC
Severity:
normal
Tags:
#1087644#5
Date:
2024-11-16 16:14:38 UTC
From:
To:
Recently I've become aware of ssh sessions no longer showing a value for "TTY"
in w(1) and loginctl list-sessions. I think this leads to issues like wall(1) /
shutdown / ... not delivering messages to the terminals of users logged in via
ssh.

Just to clarify, what I'm seeing:

17:10 ch@tiksta:~ % w
 17:10:57 up  1:30,  3 users,  load average: 0.08, 0.04, 0.07
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ch                -                15:48    1:30m  0.00s  0.10s /usr/lib/systemd/systemd --user
ch       tty2     -                17:02    8:57   0.05s  0.05s -zsh
ch                192.168.67.1     17:10    1:30m  0.00s  0.04s sshd-session: ch [priv]

The last of these entries is my session logged in via ssh. The running shell says:
17:10 ch@tiksta:~ % echo $TTY
/dev/pts/0

I would have expected w(1) to show pts/0 in the TTY column, like it did on
bookworm.  Local logins (using login) still show a TTY in w(1), for
example the second entry in above's output.

loginctl also has no info on the TTY:
17:13 ch@tiksta:~ % loginctl list-sessions
SESSION  UID USER SEAT  LEADER CLASS   TTY  IDLE SINCE
      2 1000 ch   -     796    manager -    no   -
      6 1000 ch   seat0 40849  user    tty2 no   -
      7 1000 ch   -     40920  user    -    no   -
(The last line should show pts/0 here.)

I don't know if the observed behaviour is an effect of utmp going
away, or caused by other changes in sshd. Could you please check
what's going on there?

Thanks,
Chris

#1087644#12
Date:
2024-11-16 23:32:35 UTC
From:
To:
Control: forwarded -1 https://github.com/openssh/openssh-portable/pull/403
[...]

While reading up on this I ran across
https://github.com/openssh/openssh-portable/pull/403, whose description
sounds like the same thing.

#1087644#19
Date:
2024-11-17 06:02:53 UTC
From:
To:
* Colin Watson <cjwatson@debian.org> [241117 00:32]:

Possible, but that will not fix reporting the tty to logind. I'm
wondering if something in sshd changed so that the tty is not
available/visible to PAM anymore?

If PAM knows about the tty, pam_systemd.so and pam_wtmpdb.so should
hopefully just record it.

Chris

#1087644#24
Date:
2024-11-18 00:11:41 UTC
From:
To:
I've now read up on the PR, and I think it will not solve the
problem.  Having the session recorded in wtmpdb is nice, but we
already have pam_wtmpdb for that.

who(1) talks to logind for getting currently logged in sessions.
wtmpdb is irrelevant for this.

We need that part to work (again?).

(I also think linking libwtmpdb.so into sshd is not a good idea.)

Chris

#1087644#29
Date:
2024-11-18 07:51:35 UTC
From:
To:
Fair enough.

I suspect this may be related to PAM_TTY_KLUDGE, then
(https://anongit.mindrot.org/openssh.git/tree/auth-pam.c#n760).  Maybe
as well as setting a kludged PAM_TTY for pam_auth, sshd needs to set a
proper one for pam_session?

It would be sshd-session, not sshd, so much less problematic than
pre-auth linkage.

#1087644#36
Date:
2025-02-17 02:36:26 UTC
From:
To:
Control: forwarded -1 https://github.com/openssh/openssh-portable/pull/433

I think so? Is it easy for you to build an sshd that does this?
The last time I looked at the openssh code trying to understand
where this might need to be patched in I got lost very quickly.

I just found another upstream PR, which would directly talk to
logind. Upstream doesn't seem to like it:
https://github.com/openssh/openssh-portable/pull/433

Chris