I have 2 users and their distinct ssh keys, and a ssh server only accepting keys
- user_1: a normal account with ssh and sftp accesses. Trusted. It can escape its home and download anything it can read.
- user_2: an account with sftp access only, chrooted to a directory. NOT trusted.
If user_2 connects via sftp with its own key but user_1 username, it ends up in user_1 home, and can roam anywhere from there.
How can I ensure any connections done with user_2 key will be chrooted ? Or link usernames and authorized_keys files to prevent users from borrowing others usernames ?
Match User user_2 ForceCommand internal-sftp ChrootDirectory /data2 AuthorizedKeysFile /data2/.ssh/authorized_keys Edit: Adding connection examples. Both connections use the same key. Only the username changes.
# User name = user_2 admin@laptop:~$ sftp -P 12345 -i ~/.ssh/user_2_id_ed25519 [email protected] Connected to myserver.com. sftp> pwd Remote working directory: / sftp> ls lost+found upload sftp> quit # User name = user_1 admin@laptop:~$ sftp -P 12345 -i ~/.ssh/user_2_id_ed25519 [email protected] Connected to myserver.com. sftp> pwd Remote working directory: /home/user_1 sftp> ls Documents Maildir Repository sftp> quit Edit 2: Each user has its own key pair. I made a mistake while testing this locally and did not change the key used as shown above. Yet I was able to connect
root@myserver:# cat /data2/.ssh/authorized_keys ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDQl+BIxhxKSGBTIQlwViAJ/<redacted> user_2@laptop --> user_2@myserver root@myserver:# root@myserver:# cat /home/user_1/.ssh/authorized_keys ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN2fc8bLk0+DD+qY0W/8UyMT3onybgey/<redacted> user_1@laptop --> user_1@myserver root@myserver:#
/home.user_1to use the centralized AuthorizedKeysFile asuser_2.