Results 1 to 8 of 8

Thread: sudo in a keyboard shortcut command

  1. #1
    Join Date
    Feb 2009
    Location
    Kennesaw, Georgia
    Beans
    122
    Distro
    Ubuntu 12.04 Precise Pangolin

    sudo in a keyboard shortcut command

    So I want to kill the Network Manager Process with the click of a key.

    I wrote this line and assigned it to a keyboard shortcut

    NM=`ps -e | grep NetworkManager | sed 's/ \([0-9]*\).*/\1/g'` ; sudo kill $NM

    When run in the terminal, it asks for my password, of course, but it will not work at all as a keyboard shortcut. Is there anyway to feed my password to the prompt or any other way around this?

  2. #2
    Join Date
    Jun 2007
    Beans
    1,745

    Re: sudo in a keyboard shortcut command

    Code:
    gksu killall NetworkManager
    Licat volaré si superturgum Aquila volat

  3. #3
    Join Date
    Feb 2009
    Location
    Kennesaw, Georgia
    Beans
    122
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: sudo in a keyboard shortcut command

    wow, that works perfectly, but still asks for a password. I will use this if nothing else works. Thank you.

    Still, is there any way I could add my password to the script to feed it into the password prompt?

  4. #4
    Join Date
    Dec 2004
    Beans
    1,068
    Distro
    Xubuntu 15.10 Wily Werewolf

    Re: sudo in a keyboard shortcut command

    If you edit the /etc/sudoers file with the command visudo there's a way of allowing normal users to run specific commands without requiring the su password. I don't know the syntax off-hand but it shouldn't be too hard to figured out.

  5. #5
    Join Date
    Jun 2007
    Beans
    1,745

    Re: sudo in a keyboard shortcut command

    Quote Originally Posted by Dr Belka View Post
    wow, that works perfectly, but still asks for a password. I will use this if nothing else works. Thank you.

    Still, is there any way I could add my password to the script to feed it into the password prompt?
    Probably not the best idea, but you can edit the sudoers file in /etc to give yourself perms to do this without needing the password, although I recommend against it for security reasons.
    Code:
    sudo -i
    echo "$USER           ALL = NOPASSWD: /usr/bin/killall" >> /etc/sudoers
    exit
    Licat volaré si superturgum Aquila volat

  6. #6
    Join Date
    Jun 2007
    Beans
    1,745

    Re: sudo in a keyboard shortcut command

    Quote Originally Posted by pickarooney View Post
    If you edit the /etc/sudoers file with the command visudo there's a way of allowing normal users to run specific commands without requiring the su password. I don't know the syntax off-hand but it shouldn't be too hard to figured out.
    The sudoers file is actually rather hard to figure out at first, there are examples that make it easier, but without a guiding hand you are still pretty likely to mess up what goes where.
    Licat volaré si superturgum Aquila volat

  7. #7
    Join Date
    Feb 2009
    Location
    Kennesaw, Georgia
    Beans
    122
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: sudo in a keyboard shortcut command

    Quote Originally Posted by scragar View Post
    Probably not the best idea, but you can edit the sudoers file in /etc to give yourself perms to do this without needing the password, although I recommend against it for security reasons.
    Code:
    sudo -i
    echo "$USER           ALL = NOPASSWD: /usr/bin/killall" >> /etc/sudoers
    exit
    This addition to the sudoers file did not enable me to use the killall command without a password

    I also tried these edits:

    Code:
    # Cmnd alias specification (this is an existing line)
    Cmnd_Alias KILL_CMDS = /bin/kill, /usr/bin/killall
    
    ....
    
    # Members of the admin group may gain root privileges (also an existing line)
    %admin ALL=(ALL) ALL
    
    william ALL=(ALL) NOPASSWD: KILL_CMDS

  8. #8
    Join Date
    Feb 2009
    Location
    Kennesaw, Georgia
    Beans
    122
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: sudo in a keyboard shortcut command

    bump

Bookmarks

Posting Permissions

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