Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict SSH users to a predefined set of commands after login?

Tags:

linux

shell

ssh

This is a idea for a security. Our employees shall have access to some commands on a linux server but not all. They shall e.g. have the possibility to access a log file (less logfile) or start different commands (shutdown.sh / run.sh).

Background information:

All employees access the server with the same user name: Our product runs with "normal" user permissions, no "installation" is needed. Just unzip it in your user dir and run it. We manage several servers where our application is "installed". On every machine there is a user johndoe. Our employees sometimes need access to the application on command line to access and check log files or to restart the application by hand. Only some people shall have full command line access.

We are using ppk authentication on the server.

It would be great if employee1 can only access the logfile and employee2 can also do X etc...

Solution: As a solution I'll use the command option as stated in the accepted answer. I'll make my own little shell script that will be the only file that can be executed for some employees. The script will offer several commands that can be executed, but no others. I'll use the following parameters in authorized_keys from as stated here:

command="/bin/myscript.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-dss AAAAB3....o9M9qz4xqGCqGXoJw= user@host 

This is enough security for us. Thanks, community!

like image 312
Marcel Avatar asked Dec 31 '08 09:12

Marcel


People also ask

How do I restrict users in ssh?

Limit SSH User LoginsOpen the /etc/ssh/sshd_config file. Add an AllowUsers line at the bottom of the file with a space separated by a list of usernames. For example, user tecmint and sheena both have access to remote ssh.


1 Answers

You can also restrict keys to permissible commands (in the authorized_keys file).

I.e. the user would not log in via ssh and then have a restricted set of commands but rather would only be allowed to execute those commands via ssh (e.g. "ssh somehost bin/showlogfile")

like image 157
HD. Avatar answered Oct 21 '22 08:10

HD.