Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I'm writing a script, in the script I need to use tcpdump to capture some packets however it needs root priviledge my computer is configured by school and I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2012
    Posts
    87

    how to run a command line with another user without prompts for psw


    Hi, I'm writing a script,
    in the script I need to use tcpdump to capture some packets
    however it needs root priviledge
    my computer is configured by school and I have no real root priviledge

    so I can't use sudo on my computer,like
    Code:
    sudo tcpdump ......
    I have to use a limited root username su4098
    Code:
    su su4098
    and then use user su4098 as the root, with su4098 I can use tcpdump


    since I want to run the tcpdump command in a script, I dont want to input the password mannualy

    how can I run tcpdump command with su4098 without mannually input the password?
    or specifically how can I change my username to su4098 without mannually inputing the password?

    thanks!

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by esolve View Post
    Hi, I'm writing a script,
    in the script I need to use tcpdump to capture some packets
    however it needs root priviledge
    my computer is configured by school and I have no real root priviledge

    so I can't use sudo on my computer,like
    Code:
    sudo tcpdump ......
    I have to use a limited root username su4098
    Code:
    su su4098
    and then use user su4098 as the root, with su4098 I can use tcpdump


    since I want to run the tcpdump command in a script, I dont want to input the password mannualy

    how can I run tcpdump command with su4098 without mannually input the password?
    or specifically how can I change my username to su4098 without mannually inputing the password?
    Hi,

    Will your school IT guys give you sudo access? As long as you have a (semi-)privileged root account, there is no reason they should not do this. unless they just don't want to, of course.

    If they would do it for you, it would be as simple as a sudo rule (created with the "visudo" command as root):

    Code:
    user ALL = (su4098) NOPASSWD: /sbin/tcpdump
    the first column, "user", refers to your username. then you could just do:

    Code:
    sudo -u su4098 /sbin/tcpdump
    and you should not be prompted for a password.

  3. #3
    Just Joined!
    Join Date
    May 2012
    Posts
    87
    I use visudo to edit a file called sudoer
    and add a line
    Code:
    myusername ALL = (su4098) NOPASSWD: /sbin/tcpdump
    but

    Code:
    [myusername@canard myusername]$ sudo -u su4098 tcpdump
    [sudo] password for myusername: 
    Sorry, user myusername is not allowed to execute '/usr/sbin/tcpdump' as su4098 on canard.



    Quote Originally Posted by atreyu View Post
    Hi,

    Will your school IT guys give you sudo access? As long as you have a (semi-)privileged root account, there is no reason they should not do this. unless they just don't want to, of course.

    If they would do it for you, it would be as simple as a sudo rule (created with the "visudo" command as root):

    Code:
    user ALL = (su4098) NOPASSWD: /sbin/tcpdump
    the first column, "user", refers to your username. then you could just do:

    Code:
    sudo -u su4098 /sbin/tcpdump
    and you should not be prompted for a password.

  4. $spacer_open
    $spacer_close
  5. #4
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,649
    Should your sudoers rule be
    Code:
    myusername ALL = (su4098) NOPASSWD: /usr/sbin/tcpdump
    based on your error message: Sorry, user myusername is not allowed to execute '/usr/sbin/tcpdump' as su4098 on canard.
    "I used to be with it, then they changed what it was.
    Now what was it isn't it, and what is it is weird and scary to me.
    It'll happen to you too."

    Grandpa Simpson



    The Fifth Continent

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •