Getting "Permission denied" even when using sudo command [duplicate]
I'm attempting to add a file to my /etc/apt/sources.list.d
folder and for some reason despite using sudo it still says permission denied. Here's the code I'm trying to run.
$ sudo cat >> /etc/apt/sources.list
I've also tried simply using gedit but that doesn't work either.
You are running the cat
command as root, but the output redirection takes place in your current shell which runs as your normal user account.
You have at least three options to achieve your goal of adding lines to your apt
sources:
-
Running the whole command including output redirection in a separate Bash root shell:
sudo bash -c 'cat >> /etc/apt/sources.list'
-
Using the
tee
command that copies output to a file (-a
option to append to instead of overwrite existing files) and running that as root:cat | sudo tee -a /etc/apt/sources.list
-
Using a terminal editor application like
nano
as root to modify the file:sudo nano /etc/apt/sources.list
However, it is recommended to leave your /etc/apt/sources.list
file as it is and add additional sources by creating new *.list
files inside /etc/apt/sources.list.d/
.