52
loading...
This website collects cookies to deliver better user experience
$HOME
and you have set up PAM to decrypt your $HOME
with your user login password. Now you want to SSH into your user with SSH keys but the problem is that .ssh/authorized_keys
sitting in your $HOME
is encrypted too and the sshd daemon can't access it to verify your identity. Password authentication would work though with PAM but you don't want that because of prevalence of brute-force attacks. So what do we do?$HOME
with restrictive permissions and set up sshd to require both key and password authorisation (password auth does the decryption with PAM).$HOME
to hold our public keys for each $USER
. I went for /ssh/
. Set permissions for that folder to 500 with chmod
and make sure it is owned by root./ssh/ugjka
and then put your public key inside that file like you would with .ssh/authorized_keys
. Make sure the owner is root, and permissions are 400/ssh/
instead of $HOME
. To do that we edit /etc/ssh/sshd_config
and add the following changesAuthenticationMethods publickey,password
AuthorizedKeysCommand /usr/bin/cat /ssh/%u
AuthorizedKeysCommandUser root
PasswordAuthentication
and PubkeyAuthentication
is set to Yes
ugjka
tries to login, the AuthorizedKeysCommand
directive will call cat /ssh/ugjka
(because %u
expands to the username) and will return the public key inside that file to the sshd daemon and authorisation will proceed. Then, next, according to the AuthenticationMethods
directive, the password authentication will be invoked and, if PAM is configured correctly, it will decrypt your $HOME
.