Announcement

Collapse
No announcement yet.

Ubuntu Error: Permission denied” when using sudo command

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ubuntu Error: Permission denied” when using sudo command

    I'm trying to add a file to my /etc/apt/sources.list.d folder and for some reason with using sudo it still shows error "permission denied". Following is the code I'm trying to run.
    Code:
     
     $ sudo cat >> /etc/apt/sources.list

  • #2
    The sudo relates only to the command (cat) does not open the file through the redirection operator. IF you want to add to the restricted file, you have to raise privilege on the file operation, not the cat.

    See the example
    Code:
    echo "# foo" | sudo tee -a /etc/apt/sources.list

    Comment


    • #3
      You have minimum three ways to do to adding lines to your apt sources:

      Running the entire command with output redirection in a separate Bash root shell:

      sudo bash -c 'cat >> /etc/apt/sources.list'
      By the tee command that copies output to a file and executing that as root:

      cat | sudo tee /etc/apt/sources.list
      By a terminal editor application like nano as root to change the file:

      sudo nano /etc/apt/sources.list
      Though, it is suggested to keep your /etc/apt/sources.list file as it is and add extra sources by creating new *.list files inside /etc/apt/sources.list.d/.

      Comment


      • #4
        Hi guys,
        Thanks for your replies.
        Actually I’m newbie on Linux so not sure where to from some of those commands.

        Comment


        • #5
          All things considered, the initial two do precisely the same as what you had, quite recently that the right part is running as root.
          Above mentioned third command opens nano, a simple command-line editor. You can attempt it and check whether you like it. Simply utilize whichever way you like most.

          Comment

          Working...
          X