One option is to use tokens to give each user a unique authorized_keys
file.
From man sshd_config:
AuthorizedKeysFile
Specifies the file that contains the public keys that can be used
for user authentication. The format is described in the AUTHORIZED_KEYS FILE FORMAT section of sshd(8)
. AuthorizedKeysFile
may contain tokens of the form %T
which are substituted during
connection setup. 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. Multiple files may be listed, separated by whitespace.
Alternately this option may be set to none
to skip checking
for user keys in files. The default is .ssh/authorized_keys .ssh/authorized_keys2
.
Emphasis mine.
So you can set:
AuthorizedKeysFile .ssh/%u_authorized_keys
Then for user foo
create an authorized_keys
file .ssh/foo_authorized_keys
.
A note on permissions
From man sshd:
~/.ssh/authorized_keys
...
If this file, the ~/.ssh
directory, or the user's home directory
are writable by other users, then the file could be modified or
replaced by unauthorized users. In this case, sshd will not
allow it to be used unless the StrictModes
option has been set to
no
.
So you may need to stick your keys outside .ssh/
, or else set StrictModes
to no
. If you set StrictModes
to no
make sure another user can't create an authorized_keys
for someone else, or delete the other user's authorized keys. Probably best off doing something like:
AuthorizedKeysFile .ssh_%u/authorized_keys
Create a directory .ssh_foo/
for user foo
, that only foo
can read/write.
You can choose if you want to also allow .ssh/authorized_keys
by using
AuthorizedKeysFile .ssh/authorized_keys .ssh_%u/authorized_keys
This will allow the "normal" form of authorized_keys
to still work, and an authorized_keys
file must be owned by your user and have correct permissions or it will be ignored. Still consider that it should not be possible to create an authorized_keys
file for another user, which could just mean touching the file as root so it's empty.
authorized_keys
file given that they share a home-dir?