0

In Ubuntu 22.04.3 LTS, if I log in with the credentials of the LDAP user testuser, in several different programs the path of the $HOME directory is not replaced by ~ (as instead it happens for local users).

A couple of examples:

  1. In bash, the value of PS1 is the default one:

    \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
    

but it appears as

testuser@myhost:/home/testuser$

instead of

testuser@myhost:~$
  1. In neomutt, in the left column where the mail directories are listed, their full path appears

    /home/testuser/Mail/mailbox1
    

instead of

   ~/Mail/mailbox1

However, in bash,

$ echo $HOME
/home/testuser

so the env variable HOME is somewhat recognized.

What could it be the problem?


Update

I am using sssd to manage the authentication of the LDAP users:

$ grep passwd /etc/nsswitch.conf 
passwd:         files systemd sss

The entries of the LDAP user and of a local user look very similar:

$ getent passwd testuser
testuser:*:<uid>:<gid>:Test User:/home/testuser/:/usr/bin/bash

$ getent passwd localuser
localuser:x:<uid>:<gid>:,,,:/home/localuser:/bin/bash

And

$ echo $HOME
/home/testuser/

matches the home directory specified in getent passwd testuser.

4
  • If you run getent passwd testuser, will you get a line resembling a normal /etc/passwd line but describing the LDAP user? If not, what is the output of grep passwd: /etc/nsswitch.conf? Does the home directory listed in getent passwd testuser output match the value of $HOME?
    – telcoM
    Commented Jan 10 at 14:51
  • @telcoM I edited the question with the output of the commands you mentioned.
    – BowPark
    Commented Jan 10 at 15:16
  • 1
    Are you positive this is not a Bash Prompt Special Character issue?
    – eyoung100
    Commented Jan 10 at 15:24
  • @eyoung100 No, because this issue does not regard only bash, but also other programs.
    – BowPark
    Commented Jan 10 at 16:13

2 Answers 2

5

The problem is the trailing / character in the LDAP definition of $HOME:

getent passwd testuser
testuser:*:<uid>:<gid>:Test User:/home/testuser/:/usr/bin/bash

You can demonstrate this with your local user account:

OHOME="$HOME"
cd "$HOME"

HOME="$HOME/"
cd "$HOME"

HOME="$OHOME"
[ -n "$OHOME" ] && { HOME="$OHOME"; unset OHOME; }

You'll see that once you've assigned HOME="$HOME/" the ~ swaps to an absolute path for your home directory.

3

It appears there is an extra slash at the end of the directory path in the LDAP record for the user's home directory, i.e.

/home/testuser/

instead of

/home/testuser

Yes, it is common to add a slash at the end of the directory name to indicate that it is in fact a directory, but that is just extra decoration for the user, not the standard form of the pathname.

For example, the pwd command returns the current working directory without appending a slash, basically because that is how it is returned by the getcwd() system/libc call, as required by POSIX compliance. The home directory pathname stored in the user record, whether in /etc/passwd or in LDAP, is expected to be in the same format. This allows the replacement of the home directory path by ~ with a simple string comparison and replacement operation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .