I am trying to run a command/script that requires root privileges when a non-root user logs into ssh

This unfortunately means I cannot use ~/.bashrc or /etc/bashrc

I also tried /etc/ssh/sshrc but it has the same problem, the command executes as the logged in user.

I see /etc/profile.d/ does something but not sure how to use it or if it will have the same problem.

sshd does run as root so I am hoping it can be taught to do this somehow

I do need to know the ip of the login for the command.

Thanks for any ideas!

added: sudo is not possible because it's for a non-privileged user without sudo rights

  • Please include the actual command you need to run (answers will be different for scripts and compiled binaries for example). – terdon Jul 8 '13 at 18:36
  • Setuo sudo. Use sudo ... where required. – Zoredache Jul 8 '13 at 18:38

Use pam_exec as a PAM session module.

  • Oh wow, I never knew about PAM. Reading up now, looks very promising. Any ideas how to grab the remote ip since it doesn't look like it's included in the PAM environment? – ck_ Jul 8 '13 at 18:44
  • @ck_: It's in the PAM_RHOST 'PAM item', but pam_exec exports it as an environment variable ($PAM_RHOST) as well. – user1686 Jul 8 '13 at 19:15

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.