-1

I have a problem using win-kex basic mode for Kali on WSL2, it has a connection fail. I can solve it running this command before launch: sudo mount -o remount rw /tmp/.X11-unix (Source: https://stackoverflow.com/questions/70577819/how-to-fix-the-error-error-connecting-to-the-kex-server)

I want to write a NOPASSWD line on sudoers just for avoid the password request everytime just for this command. So, searching info I found this post: Add NOPASSWD in /etc/sudoers for only some specific commands. The person who asked, edited the post and shared an answer, but when I tried to use it, visudo "explodes" the screen with a lot of errors (syntax errors, mostly) and is just because of I don't understand very well all about User_Alias, Cmnd_Alias, and others sudoers configurations.

The issue is in the sudoers.d file, so I would like an example about that point for use it as guideline.

Edit:

I already created the "win_kex" file as root on /usr/local/bin/ with this:

#!/bin/bash
mount -o remount rw /tmp/.X11-unix
#

And I created another file "winkex" on sudoers.d following the steps on the post shared before: (myusername=kapichy97)

User_Alias winkex=myusername
Cmnd_Alias WK=/home/globalisation/r
winkex ALL=NOPASSWD WK

Then added the lines on sudoers:

myusername ALL=(ALL:ALL) ALL
myusername ALL=(ALL:ALL) NOPASSWD: /usr/local/bin/winkex

And just save, exit and visudo show several errors.enter image description here

14
  • sudoers.d is NOT a file, it's a directory Jan 9 at 2:11
  • Yeah, I mean the file in that location. I create a file named winkex
    – kapichy97
    Jan 9 at 3:32
  • Can you add to the question the following. 1: the content of the file you're trying to edit, and 2: the command (exactly) you run, 3: the file owner and permissions of the file you are editing Jan 9 at 3:35
  • hmmm - odd that the the errors suggest the file has completely different content Jan 9 at 5:03
  • 1
    Consider updating the question's title so that a reader can see what the question is actually about without having to read all text.
    – Kusalananda
    Jan 9 at 7:23

1 Answer 1

0

As @JaromandaX said on comments, there's no need to make all that stuff that I found on the shared post. Just ensure that the command is right, obviously run chmod -x and check the sudoers file. So, the steps are this:

  1. Create a script with sh extension on any path (mine was win_kex.sh on /usr/local/bin)
  2. Make executable the script using chmod -x (chmod -x /usr/local/bin/win_kex.sh)
  3. Edit sudoers file using sudo visudo adding the NOPASSWD rule as the last line of file: myusername ALL=(ALL) NOPASSWD: /Path/to/the/file (kapichy97 ALL=(ALL) NOPASSWD: /usr/local/bin/win_kex.sh).

And that's all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .