createdbeats
Posts: 1
Joined: Thu Dec 19, 2019 2:52 am

Cannot save a file in text editor - Access Denied

Thu Dec 19, 2019 2:56 am

Hello,

I have never used a linux system and still finding my way around the system. I need to save a text file but both Text Editor and Geany give me an access denied error when trying to save.

Not sure what is going on.

I am trying to save a file into the /etc/apt/source.list.d folder.

Thanks for the help, as I cannot find anything on this online.

MarkDH102
Posts: 377
Joined: Fri Feb 13, 2015 3:18 pm

Re: Cannot save a file in text editor - Access Denied

Thu Dec 19, 2019 7:10 am

Open up a terminal window.
Type:

Code: Select all

cd /etc/apt/source.list.d

Code: Select all

sudo nano yourfilename
When you are done, to save press CTRL-X and then Y.

To modify/create files in these 'system' areas you need to be a super user (I think that's the correct term), hence running all file type commands in there preceded by sudo.

bjtheone
Posts: 454
Joined: Mon May 20, 2019 11:28 pm
Location: The Frozen North (AKA Canada)

Re: Cannot save a file in text editor - Access Denied

Thu Dec 19, 2019 1:54 pm

Do some reading about file system permissions. A very simplistic explanation is:

Linux has the concept of 3 levels of permissions (user, group, other). Each level can be set to no access, read only, read & write, or execute. You must have read access to look at the file. You must have write access to save the file. You must have execute access to run/execute the file. This is further complicated by the permissions of the directories.

Most system level files are owned by user "root", and regular users only have read or read & execute to them. This is done to avoid regular users from accidentally (or deliberately) breaking the system or changing other users stuff (remember Linux is intended to be a multi-user system).

As mentioned if you have a default Pi setup, you are running Raspbian, and the standard regular user is "pi". You can use the "sudo" command to get elevated privileges (equivalent to root) to do stuff, like edit and save system files. You DO NOT want to just run all your commands using sudo.

klricks
Posts: 6771
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Cannot save a file in text editor - Access Denied

Thu Dec 19, 2019 4:42 pm

createdbeats wrote:
Thu Dec 19, 2019 2:56 am
Hello,

I have never used a linux system and still finding my way around the system. I need to save a text file but both Text Editor and Geany give me an access denied error when trying to save.

Not sure what is going on.

I am trying to save a file into the /etc/apt/source.list.d folder.

Thanks for the help, as I cannot find anything on this online.
As mentioned you have to use sudo when editing a file that is not in the users /home directory.

For the GUI 'text editor' (Leafpad) or geany:

Code: Select all

sudo leafpad
sudo geany
Or use the nano editor as mentioned.

Note it is not recommended to make changes to the sources list. Doing so is one of the fasted ways to trash your OS into an unusable state.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

bjtheone
Posts: 454
Joined: Mon May 20, 2019 11:28 pm
Location: The Frozen North (AKA Canada)

Re: Cannot save a file in text editor - Access Denied

Thu Dec 19, 2019 8:26 pm

klricks wrote:
Thu Dec 19, 2019 4:42 pm

As mentioned you have to use sudo when editing a file that is not in the users /home directory.

Note it is not recommended to make changes to the sources list. Doing so is one of the fasted ways to trash your OS into an unusable state.
Pedantically, you need to use sudo when attempting to to perform actions that your current user does not have access rights (permissions) to do so. This is complicated by permissions on directory and sticky bits, but you certainly will have read/write access to places other than your home directory. However, a large flag should go up when you do not have access to a file as a regular user. Should you be changing this file? Do you understand the the impact? Could you achieve the same result by adding the appropriate configuration file in your account rather than changing the system level one?

The second point should be in giant glowing letters. If you do not fully understand the ramifications of doing so, do not muck about with the sources list. You can end up installing apps from a different repo than the standard one or totally mucking up dependencies. If you absolutely need to install an apt from another repository, add it, install the app, then comment out the repo. If you stick to the standard RPT provided repositories you get software that will work on the Pi and that has been tested to play nicely with all the standard OS programs. Software from elsewhere may work without issue, it should work if it has been complied for ARMH, especially if it is Debian based, but it may not. If you have a good grasp of how Linux works it is not a big deal. If you are just starting out you may create tricky issues that are hard to debug and fix.

Return to “Beginners”