SSH pubkey authentication works only if another session is already open

Solution 1:

It seems your home directory or the place where your keys are, is encrypted. The first login mounts and decrypts the directory letting the ssh daemon use the keyfile.

Solution for that is to move the "authorized_keys"-file to a device where it is not encrypted by default.

After that you have to point the ssh daemon to that place. The following configuration option is used for that.

AuthorizedKeysFile Specifies the file that contains the public keys that can be used for user authentication. AuthorizedKeysFile may contain tokens of the form %T which are substituted during connection set-up. The following tokens are defined: %% is replaced by a literal '%', %h is replaced by the home directory of the user being authenticated and %u is replaced by the username of that user. After expansion, AuthorizedKeysFile is taken to be an absolute path or one relative to the user's home directory. The default is “.ssh/authorized_keys”.

Maybe like this

AuthorizedKeysFile /etc/ssh/%u/authorized_keys