Whilst initializing token as a non-root user, we invariably try to access the default /etc/softhsm/softhsm2.conf which points tokens to be staged under /var/lib/softhsm/tokens whose ownership/permission is limited to be used by root and its associated groups.
Changing ownership/permission of /var/lib/softhsm/tokens doesn't solve the problem as we cannot access /etc/softhsm/softhsm2.conf in the first place given the access limitation, so we should be doing this instead:
cd $HOME
mkdir -p $HOME/lib/softhsm/tokens
cd $HOME/lib/softhsm/
echo "directories.tokendir = $PWD/tokens" > softhsm2.conf
export SOFTHSM2_CONF=$HOME/lib/softhsm/softhsm2.conf
$ softhsm2-util --init-token --slot 0 --label "test" --so-pin 5462 --pin 8764329
The token has been initialized.
Whilst initializing token as a non-root user, we invariably try to access the default
/etc/softhsm/softhsm2.conf
which points tokens to be staged under/var/lib/softhsm/tokens
whose ownership/permission is limited to be used by root and its associated groups.Changing ownership/permission of
/var/lib/softhsm/tokens
doesn't solve the problem as we cannot access/etc/softhsm/softhsm2.conf
in the first place given the access limitation, so we should be doing this instead: