Saving write protected files in Linux (Arch Linux)


#1

Is there any way of bypassing the error that pops up?
Susave package isn’t working apparently.


#2

No, you cannot bypass. What you can do is give your account the permissions it needs and/or change the ownership and permissions of the files to match the account atom uses when connected to linux. That is the only way. There are a million ways to do it, so I have laid out the basics. if it is too much right now ,that is good, take and nap and deal with it when you get up. The problem will be waiting for you.

It is not hard but it looks like a lot to grasp at first glance.

Do you have access to the command line with root privileges? If not, this becomes tricky or impossible. What I do is just go to the directory and use a chown to set the owner of the files and directories to match the account Atom is using to connect to Linux. Sometimes, file permissions have to be changed with chmod.


#3

Long and Short of It
I just looked up Arch Linux and see it is normal Linux. These are the basics of linux permissions. Believe me you will catch on and this information will server you for many many years. This system was setup a long time ago. Some things have been added. This article boils it down great.

In case you unfamiliar with how linux permissions work, I am going to explain a couple basics. When first seeing them, my reaction was “what the hey?” As soon I read an explanation, reaction changed to “oh, ok, that isn’t too bad.” However, I had to be in the right frame of mind to take this in.

The basic permissions in linux are yes/no for read, write, and execute. No trick there. Those permissions get applied to every file and directory. If you list files from the command line with with ls -al, you get a list like this:

image
For reasons not disclosed to me, Unix peoole, the ones who came before Linux, like to make their text really small. I think it is to allow more on a screen.

The other two things you need to know are

1, how these translate into numbers, like what 755 means.

  1. What the commands are for applying ownership and permissions

First the numbers. r=4. w=2 x=1 For each of the three permission sets on a file or directory, you add them up;

so 761 means

owners have read -write - execute
group members have read and write
others have only execute.
There numbers are setup this way so they can only add one way… There no way to get 6 out of these number except with read and write. You cannot have two execute to do rxx. The first position always is r or -. Then it is w or - and then x or dash. That makes
7=rwx
6=rw
5=rx
4=r
3=x
2=w
1=x
0=no permissions

You find which of those numbers applies to each of the three permissions on a file or directory, that will give you three of those numbers. three times for each file and directory, that is how you get permissions in all the combinations there are.

r-x-wx— is 530
--------- is 000
rwx rwx rwx is 777
rwx rwx -rx is 775
I put space between the three sets to make it easier to see usually no spaces are shown’

COMMANDS TO SET THESE THINGS
A lot of editors let you set permissions owner and groups. I just checked there is a package for atom called chmod.
image

chmod for change mode is the command for setting permissions. That package will do it for you. if you have to type it, chmod 755 <path to files/directories where to apply the permission> Put -R before the permission to do it recursively.

To set owners and groups, use chown (change owner). The owners in the exampole directory I showed you were set like this
chown -R dan:www-data *

YOUR BOMB
The error you are getting is caused by the fact that whatever account you used to signin, it does not have the permissions for the files and directories you are trying to edit. If you set them so only you have permission, that is going to prevent other accounts from using the system. If you are developing a website, you have to share permissions with the web server. The way I handle this is I own the files and put myself into the apache groups then set the permissions so we can both read write and execute. No one else needs write access so that means 775. People will say not give apache write access, but if you do that, I am sure there is a way but I don’t know what it is, there are times when my web app needs to write files so I let apache have write permissions. I guess the problem is that if someone hacks in and gets control of the apache account it would be bad. There are ways to prevent unauthorized logins, I rely on them.

I hope this helps;


#4

Thanks a lot for the big guide/reply.
Now I understand what each part does (rwx).
I was hoping there would be a way to enter the root password when needed like sublime text does.


#5

I don’t believe that Atom has this functionality built in, but it would definitely be useful for some cases. It’s true that a variety of Linux setups involve routine editing of files that are kept behind sudo for the sake of hygiene, and even though most people who use Linux with that much emphasis on the command line are frequently the same people who are fluent in either emacs or vi, it would be nice to be able to use Atom to edit those things. In my personal practice, I’ve just used sudo nano when I needed to change a protected file.

Here’s the great thing about Atom being built on web tech. It’s possible to find where the save function is defined in code. Since it’s in CoffeeScript, it’s easy enough to read and understand. We can also see that there’s a line that does give an elevation prompt on Mac, so it seems like it should be easy enough to do the same thing for Linux.


#6

Something like this image is a must-have for Atom. It’s part of the text/file manipulation thing I keep rattling about.
image

In addition to prompting for passwords when needed, there is a way to fit a password for sudo with the ability to change permissions and owners.


#7

I think that’s a great package idea. I don’t expect that the dev team would want to invest coding time into features like that, but as a package it would work well.

It would be fairly easy to have a context menu entry that toggles a package view with permissions displayed, then give it the ability to run commands on the back end. There would need to be two or three business logic files (I don’t know Mac well enough to know if it differs from Linux; @danallen?) and it would be necessary to make deliberate calls regarding the expected security of a package like that. Should it require the user to enter their password every time? Should it remember the password for a single session? Should it remember the password forever? Should the password be displayed or obscured? Should it encrypt the password? You can serialize() any variables held by your package, so you could take a password and store it unencrypted forever.

Edit: Saving for reference later: cacls is the command for Windows.