Kali Linux

How to Fix zsh: permission denied: /etc/apt/sources.list Error on Kali Linux

How to fix zsh- permission denied on Kali Linux

Zsh is a default shell on the Kali Linux system that allows you to run commands and perform your required tasks with ease. However, while working on Zsh in Kali Linux, you may encounter “zsh: permission denied: /etc/apt/sources.list” error while adding a repository to the system repository list. This type of error occurs when you try to modify the system sources.list file without sufficient privileges. It prevents you from adding the required repository, thus you won’t be able to install the required application or package on your system.

Worry not, read this guide for finding how to fix the “zsh: permission denied: /etc/apt/sources.list” error on Kali Linux system.

Quick Outline

Why “zsh: permission denied: /etc/apt/sources.list” Error Occurs

When you add a repository with echo command followed by repository URL into the source repository with sudo privileges, you will encounter the following error:

sudo echo 'deb http://www.duinsoft.nl/pkg debs all' >> /etc/apt/sources.list

This error occurs because users don’t have required permission to add the repository even with the sudo privileges. It is because the sources.list file can be modified only by the root user. You can use the ls command provide below to check for the necessary permission for sources.list file:

ls -l /etc/apt/sources.list

 

When you run the sudo command with echo mode, the echo command will run as a root but the command to append the repository to sources.list file is run as a normal user. Thus, due to conflict and requiring permission issues, you will experience that kind of error.

How to Fix “zsh: permission denied: /etc/apt/sources.list” Error on Kali Linux

To fix the “zsh: permission denied: /etc/apt/sources.list” error on Kali Linux, you can:

1: Run tee Command with sudo Privileges

The most straightforward approach to fix “zsh: permission denied: /etc/apt/sources.list” error is to run the echo command as a root user, and giving the sudo privileges to tee command, as shown below:

echo 'deb http://www.duinsoft.nl/pkg debs all' | sudo tee -a /etc/apt/sources.list

2: Manually Add Repository Inside the sources.list File

Another approach to fix the “zsh: permission denied: /etc/apt/sources.list” error is to open the sources.list file with root privileges. This allows you to edit the sources.list file, such as adding a repository according to your choice. You can open sources.list file on Kali Linux via nano editor from the provided command:

sudo nano /etc/apt/sources.list

After the changes, you can save the file using CTRL+X, approve the changes using Y and close the file using the Enter button. Once done, update the repository on Kali Linux using the following command:

sudo apt update

3: Create a Separate File

Besides editing the main source file, you can also fix the “zsh: permission denied: /etc/apt/sources.list” error by creating a separate file on Kali Linux. It can be done from the below-given touch command that creates a repository.list file inside the sources.list.d location:

sudo touch /etc/apt/sources.list.d/duinsoft.list

Then adding the repository to Kali Linux source repository location by running echo as a root user and tee command with the sudo privileges:

echo 'deb http://www.duinsoft.nl/pkg debs all' | sudo tee -a /etc/apt/sources.list.d/duinsoft.list

By doing this process, you are leaving the main sources.list file alone, however, it will add the sources through an included file that will handle the added repository.

4: Add a Repository as a Root User

Besides adding the repository inside the sources.list file with root privileges, you can manually enter the system as a root user using the following command:

su

Then add the required repository using the echo command without giving sudo privileges:

echo 'deb http://www.duinsoft.nl/pkg debs all' >> /etc/apt/sources.list

Further, you can also manually add the repository as root user by using the sudo su command followed by the -c argument:

sudo su -c "echo 'deb http://www.duinsoft.nl/pkg debs all' >> /etc/apt/sources.list"

5: Create a Script File

You can also create a script file in Kali Linux, add the repository command, and then run the script to add the required repository to the source repository location. The complete process can be followed using the following steps:

Step 1: First, create a script file in Kali Linux with .sh extension using nano editor from the below command:

sudo nano script.sh

Inside the script file, first add the bash line:

#!/bin/bash

Then add the repository with the echo command:

echo 'deb http://www.duinsoft.nl/pkg debs all' >> /etc/apt/sources.list

Once done, save the script file using CTRL+X, then add Y for approving the changes and press Enter to close the file:

Step 2: Then give execute permission to the script file you created in the previous steps, it can be done using the chmod command:

sudo chmod +x script.sh

Step 3: Now, run the script file with sudo privileges to successfully add the repository to the system:

sudo ./script.sh

In this way, you can fix the “zsh: permission denied: /etc/apt/sources.list” error on Kali Linux system.

Conclusion

“zsh: permission denied: /etc/apt/sources.list” error occurs in a system because a normal user doesn’t have permission to make changes to the source repository file. If you are using the Kali Linux system and encounter this error, you can fix it by running the tee command with sudo privileges. Besides that, you can manually add a repository or consider a separate file for adding repository. Alternatively, you can also add the repository by login as a root user or create a script, add the repository and execute the script to successfully add the repository to the Kali Linux system. A detailed description of all five methods are presented in the above-section of this guide.

Similar Posts