Linux – How to grant permission to edit files in Windows Subsystem Linux using Visual Code

debianfile-permissionskali-linuxlinuxwindows-subsystem-for-linux

I want to edit the \etc\apt\sources.list file in my Kali distro.
I have the windows insider update and I am running WSL version 2. I have installed the vscode remote extension.
When I try to save the file I edited, it shows me-

Failed to save 'sources.list'. Unable to write file (NoPermissions (FileSystemError): Error: EACCES: permission denied, open 'etc\apt\sources.list')

Best Answer

You got an Error: EACCES: permission denied error message because you tried to edit files owned by root in a GUI app (Visual Studio Code). Editing files owned by root in a GUI app can cause file corruption.

Open the terminal, change directories with cd /etc/apt/ and run the following command:

sudoedit sources.list  

sudoedit opens nano editor in the terminal by default in Kali Linux. The instructions for using nano editor are always found at the bottom of every page. The only two nano keyboard shortcuts that you need to know are for WriteOut and Exit. Press the keyboard combination Ctrl+O and after that press Enter to save the file being edited. Press the keyboard combination Ctrl+X to exit nano.

Related Question