0

I want to create a user who can log into my server and run the specific command only.

Let say I already have a user user_xyz and his home folder is

/home/user_xyz/

now inside that home folder, there is another folder public_html folder.

Now I want to add user say developer and his home folder is

/home/user_xyz/public_html

developer user can only be logged in through ssh and can not access outside of its home folder and can only run only below command

  1. composer install
  2. composer update
  3. mkdir

closed as too broad by Ipor Sircer, user34720, Jakuje, Kusalananda, GAD3R Jan 17 '17 at 21:54

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    You can do it by configuring ~/.ssh/authorized_keys, you can set a command for each key. That command would have to handle execing one of the 3. – ctrl-alt-delor Jan 17 '17 at 16:33
  • 2
    Putting a home directory in a home directory seems like a bad idea, and not what you need. You can however use a link from one to the other. ln -s /home/developer/public_html /home/user_xyz/. Also check that your file permissions are set up correctly. – ctrl-alt-delor Jan 17 '17 at 16:36
  • 2
    If your user developer cannot access anything outside the desired directory, they cannot execute /bin/mkdir. You can probably put them into a chroot jail on login, though. – Ulrich Schwarz Jan 17 '17 at 17:01
1

Create your user and use bash's restricted shell /bin/rbash for their shell (*).

Now, craft their home directory with only what they need:

  • a bin directory with the binaries they are allowed to use
  • a startup script (.profile, etc) that defines PATH to be that directory, and that undefines (or redefines) all shell builtins that you don't want them to use

That's the idea.

(*) With only three commands, you may also want to create your own shell.

-1

Yes, you can set a specific directory as users home directory by below command

useradd -d /home/user_xyz/developer developer

and for limited command access, open file name as

vi /etc/sudoers

or simply run command

visudo

Edit the file, you can find lines to provide control or limited command access to limited user.

Not the answer you're looking for? Browse other questions tagged or ask your own question.