Using Linux and Openssh:

A user can connect using ssh to a server on which his key is in the authorized_keys list. His public key is preceded by command="command..." which forces execution of a specific command (non-shell):

command="/path/to/somescript...",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-user-rc ssh-rsa AAAff...................

  • Is there a way that the user can bypass this command?
  • What about sftp? Does sftp work when using a forced command (which is not a shell)?
| improve this question | | | | |

If the allowed command set includes the sftp daemon (or internal-sftp), then SFTP would be allowed. However, if you're setting the forced command in the authorized_keys file and the user had sftp access, without additional work they could replace the file with one not restricted to what you define. This would of course work with any application that the user can instruct to modify that file (intentionally or by tricking it). A better option may be to restrict by user or group within the main sshd_config, possibly with ChrootDirectory.

| improve this answer | | | | |
  • +1 for "restrict by user or group within the main sshd_config". – Alex Holst Jan 26 '11 at 14:24

The most common threat comes from allowing them to use a command is capable of doing things the admin hadn't thought about. For example, CVS and SVN allow for pre/post commit scripts to run. If a user can modify a post-commit script, he can run his own commands.

| improve this answer | | | | |

you can set an attribute using chattr on the .ssh folder and the authorized_keys file after you have made the required entries to the authorized_keys file, so this way nobody will be able to make any changes or even overwrite the .ssh folder or even the authorized_keys file.

you can do a recursive chattr:

chattr -R +i .ssh
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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