Categories
SysOps

How to alter date format when listing cached Kerberos tickets

Alter date format when listing cached Kerberos tickets.

Sometimes it is hard to read ticket information when it is displayed using US date format and you live in Europe (month/day/year versus day/month/year issue).

$ klist
Ticket cache: FILE:/tmp/krb5cc_10000_ycdwd4
Default principal: octo@OCTOCAT.LAB

Valid starting       Expires              Service principal
10/05/2021 20:05:49  10/06/2021 06:05:49  krbtgt/OCTOCAT.LAB@OCTOCAT.LAB
        renew until 10/06/2021 20:05:49

Display locale settings.

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Use localized TIME format.

$ LC_TIME=pl_PL.UTF-8 klist
Ticket cache: FILE:/tmp/krb5cc_10000_ycdwd4
Default principal: octo@OCTOCAT.LAB

Valid starting       Expires              Service principal
05.10.2021 20:05:49  06.10.2021 06:05:49  krbtgt/OCTOCAT.LAB@OCTOCAT.LAB
        renew until 06.10.2021 20:05:49

Ensure that localized time will be preserved.

$ echo "export LC_TIME=pl_PL.UTF-8" | tee -a ~/.profile

Potential issues

Beware, you need to generate the localization files for the used language.

In this example using LC_TIME to alter the date and time formatting does not work.

$ LC_TIME=de_DE.UTF-8 klist
Ticket cache: FILE:/tmp/krb5cc_10000_ycdwd4
Default principal: octo@OCTOCAT.LAB

Valid starting     Expires            Service principal
10/05/21 20:05:49  10/06/21 06:05:49  krbtgt/OCTOCAT.LAB@OCTOCAT.LAB
        renew until 10/06/21 20:05:49

Generate the missing localization files for this specific language using TUI.

$ sudo dpkg-reconfigure locales 

Now it will work as expected.

$ LC_TIME=de_DE.UTF-8 klist
Ticket cache: FILE:/tmp/krb5cc_10000_ycdwd4
Default principal: octo@OCTOCAT.LAB

Valid starting       Expires              Service principal
05.10.2021 20:05:49  06.10.2021 06:05:49  krbtgt/OCTOCAT.LAB@OCTOCAT.LAB
        renew until 06.10.2021 20:05:49