How to run command as different user

czerny

Is it possible to run a command

  • with parameters first of which starts with - (dash) e.g. /usr/bin/echo -n foo
  • as different user and group, for example apache:apache
  • using command su
  • when login shell is set to /sbin/nologin ?

I tried:

  • su -s "/usr/bin/echo" -g apache apache -n foo
    • fails with su: invalid option -- 'n'. It looks like first argument may not start with dash.
  • su -c "/usr/bin/echo -n foo" -g apache apache
    • fails with nologin: invalid option -- 'c'. It looks like -c can't be used if login shell is /sbin/nologin
czerny
su -s /bin/bash -c "/usr/bin/echo -n foo" -g apache apache
  • -s /bin/bash overrides nologin and allows to interpret value of -c option
  • -c "/usr/bin/echo -n foo" allows to avoid using dash-starting first argument

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Is sed run as a different user?

분류에서Dev

Run a command in the context of a different app

분류에서Dev

Docker doesn't RUN command as USER

분류에서Dev

How do I remove multiple Smart Card entries in the "run as different user" dialog?

분류에서Dev

How to run command on connect to network

분류에서Dev

How to run a command in background always?

분류에서Dev

How to know the command run by a process?

분류에서Dev

Run as different user from Windows 10 Start Menu

분류에서Dev

Command behavior is different when executed by an other user (via su -c)

분류에서Dev

How to run a command or script at screen lock/unlock?

분류에서Dev

How to run a VirtualBox VM from command line?

분류에서Dev

How to run batch file command with elevated permissions?

분류에서Dev

How to run this curl command using Net:HTTP

분류에서Dev

How to include a Java command in ANT to run the project

분류에서Dev

How to run ''top'' command 1 time and exit?

분류에서Dev

How to find the full path of sudo to run a command

분류에서Dev

How to run complicated batch command using "subprocess"

분류에서Dev

How to run bash command with arguments at scheduled time

분류에서Dev

How are chown and chmod command different in the given operation?

분류에서Dev

How to use paste command for different lengths of columns

분류에서Dev

How to iterate a command with two different variables?

분류에서Dev

How is rm command different from the delete button?

분류에서Dev

How to make ubuntu service run as specific user

분류에서Dev

How to run the btsync service as the local user?

분류에서Dev

"Last" command: How to show latest user login?

분류에서Dev

How to block a common user use startx command?

분류에서Dev

How to automatically run a specific command on Live USB on boot?

분류에서Dev

How do I run an arbitrary shell command from Deno?

분류에서Dev

How detect failure of Web Performance Test run from command line

Related 관련 기사

  1. 1

    Is sed run as a different user?

  2. 2

    Run a command in the context of a different app

  3. 3

    Docker doesn't RUN command as USER

  4. 4

    How do I remove multiple Smart Card entries in the "run as different user" dialog?

  5. 5

    How to run command on connect to network

  6. 6

    How to run a command in background always?

  7. 7

    How to know the command run by a process?

  8. 8

    Run as different user from Windows 10 Start Menu

  9. 9

    Command behavior is different when executed by an other user (via su -c)

  10. 10

    How to run a command or script at screen lock/unlock?

  11. 11

    How to run a VirtualBox VM from command line?

  12. 12

    How to run batch file command with elevated permissions?

  13. 13

    How to run this curl command using Net:HTTP

  14. 14

    How to include a Java command in ANT to run the project

  15. 15

    How to run ''top'' command 1 time and exit?

  16. 16

    How to find the full path of sudo to run a command

  17. 17

    How to run complicated batch command using "subprocess"

  18. 18

    How to run bash command with arguments at scheduled time

  19. 19

    How are chown and chmod command different in the given operation?

  20. 20

    How to use paste command for different lengths of columns

  21. 21

    How to iterate a command with two different variables?

  22. 22

    How is rm command different from the delete button?

  23. 23

    How to make ubuntu service run as specific user

  24. 24

    How to run the btsync service as the local user?

  25. 25

    "Last" command: How to show latest user login?

  26. 26

    How to block a common user use startx command?

  27. 27

    How to automatically run a specific command on Live USB on boot?

  28. 28

    How do I run an arbitrary shell command from Deno?

  29. 29

    How detect failure of Web Performance Test run from command line

뜨겁다태그

보관