Allow a UNIX group access to only a single file through SSH
Solution 1:
My solution was to follow Kenneth's comment and set up lshell
—was pretty easy and quick to do.
- Run
sudo apt install lshell
to getlshell
- Create a UNIX group (e.g.
sudo groupadd testgroup
) - Add necessary user(s) to your group (e.g.
sudo usermod -a -G testgroup username
) - Also add the user(s) to the
lshell
group (e.g.sudo usermod -a -G lshell username
) - Edit
/etc/lshell.conf
with the desired configuration (see below) - Set
lshell
as the default shell for the user(s) (e.g.chsh -s /usr/bin/lshell username
)
With the below configuration, testuser
can only run script.py
after logging in through SSH. They can't connect with SCP/SFTP or browse the file structure through the shell.
[grp:testgroup]
login_script : "python /some/path/script.py"
path : "/some/path/"
forbidden : ["ls", "echo", "cd"]
scp : 0
sftp : 0