Score:0

kill process without inputting password

ru flag

EDIT
I ran the following:

$ echo $USER
goldy
$ hostname
goldy-ThinkPad-X1-Carbon-6th

$ sudo visudo -f /etc/sudoers.d/kill and added goldy goldy-ThinkPad-X1-Carbon-6th = (root) NOPASSWD: /bin/kill

And tried rebooting. Still what I run kill I'm asked for a password.

Tho I notice this:

$ sudo cat /etc/sudoers | grep includedir 
#includedir /etc/sudoers.d

I didn't want to remove # without being sure I'm not screwing anything up :)

Is that the missing step?

Because It seems like that directory should be included by default:

$ sudo cat /etc/sudoers.d/README
# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on
# installation of the package now includes the directive:
# 
#   #includedir /etc/sudoers.d

OP
I have the following shell function to kill a port

function kill-port {
  PORT=$1
  sudo kill -9 $(sudo lsof -t -i:$PORT)
}

How can I run it w/o the need to input a password?

I've seen here how to use pkill w/o password, how do I do the same for kill?

ru flag
You can't kill a process that is not running under your user without `sudo`. That's intentionally done that way, you need to use `sudo` to terminate the process if it's not owned by you.
ru flag
I saw a way to add `pkill` to a user, so why not `kill`?
muru avatar
us flag
@AdamGoldman what way?
ru flag
see here https://askubuntu.com/questions/520072/run-pkill-without-sudo-permission
ru flag
That 'way' is to modify the sudoers to permit the user to execute pkill as sudo without needing a password. It still requires *sudo* to work, it didn't actually 'grant' the ability to run `kill` as the user, they still need to call it with `sudo` to work.
ru flag
that's actually what I want, updated the question to reflrect that
ru flag
Updated the OP with the steps I did according to that link, it still asks for a password. Details in the **Edit** Section of the OP
muru avatar
us flag
You're running `sudo kill` and `sudo lsof`. Who's going to add the NOPASSWD rule for `lsof`?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.