0

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?

goldylucks
  • 632
  • 2
  • 12
  • 23
  • 1
    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. – Thomas Ward Aug 13 '21 at 02:13
  • I saw a way to add pkill to a user, so why not kill? – goldylucks Aug 13 '21 at 06:02
  • @AdamGoldman what way? – muru Aug 13 '21 at 06:10
  • see here https://askubuntu.com/questions/520072/run-pkill-without-sudo-permission – goldylucks Aug 13 '21 at 06:20
  • 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. – Thomas Ward Aug 13 '21 at 18:29
  • that's actually what I want, updated the question to reflrect that – goldylucks Aug 14 '21 at 01:33
  • 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 – goldylucks Aug 14 '21 at 05:36
  • You're running sudo kill and sudo lsof. Who's going to add the NOPASSWD rule for lsof? – muru Aug 15 '21 at 07:15

0 Answers0