LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-21-2018, 10:12 PM   #1
ref-x
LQ Newbie
 
Registered: Apr 2018
Posts: 3

Rep: Reputation: Disabled
Thumbs up What is an Ideal permissions and groups for a linux configuration


I really need an expert help. First time running my own VPS, afraid of everything.

The story:

1.Bought a small server from Linode lastweek.
2.Installed debian 8, setup lamp, setup my sites, domains and stuff.
3.Everything is working good but it's extremely hard to maintain the site because of permissions.

As I am a windows user at home, I am accessing my linode server thru two ways:
1. WinSCP
2. SmartTTY

I got 3 different users I need to wrestle every day (nobody other than me accessing the server, I am the sole admin):
Root
MyUser (sudo)
www-data (which apache created)

www-data and MyUser are in the same group

As root and www-data login is disabled I need to login with "MyUser", and sudo if needed. if I transfer anything to server with SCP, that file automatically belongs to "MyUser" and and that file doesn't have group write permissions by default. Then I have to give that file +g so apache can write to it.

And every moment in my last week, went past as I struggle with permissions.

and tonight I was trying to add a /etc/cron.daily job. Yet that directory belongs to "root", and "root" doesn't belong to any group, I need to sudo every command I give to create a blank file, retype file in nano. Because I couldn't be able to upload the file to that directory.

I am kind of afraid of relaxing the permissions, as my server sits in the wild like this, open to threats. But I am very close to giving all files to 777.

Then I wonder, maybe I'm doing something wrong. Is this that awaits me? Is this a life of a linux user, fighting with permissions, every day at every hour?

How do I survive? Can you give me a permission advice? do I need to add "MyUser" to root group? of what if change the ownership of all directories to "MyUser"? What is the security risk regarding using 775 (which I'm using time to time).

TLDR; so here is a short version:

I want to control my server without permissions get in my way, but without generating any security holes. Is it possible?
 
Old 04-22-2018, 11:29 PM   #2
mpapet
Member
 
Registered: Nov 2003
Location: Los Angeles
Distribution: debian
Posts: 548

Rep: Reputation: 72
I know this isn't the answer you want, but, the account running a service that is exposed to a hostile Internet and you want that account walled off from the rest of the system.

I would not advise adding your user account to the account running apache.
 
1 members found this post helpful.
Old 04-23-2018, 12:03 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,330
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by ref-x View Post
I want to control my server without permissions get in my way, but without generating any security holes. Is it possible?
Yes, but you'll have to set the permissions to enable you to do your job without getting in the way. For any of us to give more specific advice on that, we'd have to know more about what you plan to do and a little about your work flow. However, there is some generic advice:

First, remove extra users from the www-data group. Only the www-data account should be in it. Its purpose is to be an unprivileged account for the HTTP daemon to use. It has read-only access to the web server's document root, if you have not changed the default directory permissions there yet. The concepts involved there are "least privilege" and "privilege separation".

Second, if it were my server, I'd make a second, less privileged account and use that to connect and for daily work. I'd only use the privileged (sudo) account after logging in through the unprivileged account and actually block it from a direct connection for defense in depth / layered security. Use AllowGroups or AllowUsers in the SSH daemon's configuration file to allow only the unprivileged user remote access. Then use "su" to become the admin user as needed. See "man sshd_config"

Third, why do you want Apache to write to the files you have uploaded? In normal operation, it only needs read access. What problem are you trying to solve? If you want to write your own files to the web server's document root, then you not Apache need write permissions to the relevant directories for your account. And if it's just you, you can chown those directories and that is enough. If you will have more than one user sharing those directories it is a little trickier on GNU/Linux than on the BSDs or on (defunct) Netware. See this blog post if that is your goal.

Let us know and we can provide more specific advice and tips.
 
Old 04-23-2018, 12:20 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by ref-x View Post
TLDR; so here is a short version:

I want to control my server without permissions get in my way, but without generating any security holes. Is it possible?
if you are just starting with all this, i strongly recommend to stick to the most conservative and wide-spread approach there is; often years later i found out that this was the right (safest) approach after all, even if it felt cumbersome at the time.

in other words, if apache documentation tells you to have these three users, that's how you should do it.
 
1 members found this post helpful.
Old 04-23-2018, 02:22 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
One more aspect: remember, if it was hard for you it will be also hard for an intruder (hopefully). but if you make it easy for yourself you will make it easy for others too.
it is not fighting with permissions but (unfortunately) fighting against intruders.
 
Old 04-23-2018, 03:12 AM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
My very public webserver utilizes three users:
1. root
2. an unprivileged user that owns and maintains the web content files* The "website owner"
3. the apache user...mine is "nobody" (it's a very old server), yours is www-data

*There a actually several of these, as there are different users for multiple websites.

"owner" files are 644/755 They are not members of the apache user group. As has been stated, the web server only needs to be able to read those to serve them...it does not need write access to them.
The only files that are owned by the apache user are those created by CGI scripts on websites. (We do a lot of web-based application development)...and those can be chowned after creation to an "owner" if that's appropriate.
When I do maintenance on the web server, I su - to do it, otherwise, interaction with content is as an "owner"

If you're using WordPress, there are some additional considerations, I got this from somone's signature here: WordPress Security

From windows, I use PuTTY and WINSCP. If I need to change the server config, I use PuTTY to ssh to the server, su -, tweak what I need and exit. That's fairly infrequent. You shouldn't need to mess with the server configuration often.

All other maintenance is of the "owner" files (at least the one's I maintain...some customers maintain their own) and is done via WINSCP using sftp. I do not have to modify files once uploaded (or updated "in place" which is what can happen with WINSCP)

Last edited by scasey; 04-23-2018 at 03:14 AM.
 
1 members found this post helpful.
Old 04-23-2018, 04:54 AM   #7
ref-x
LQ Newbie
 
Registered: Apr 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
thanks for your replies, I think I kind of understand the seriousness of the situation.

Quote:
Originally Posted by Turbocapitalist View Post
First, remove extra users from the www-data group. Only the www-data account should be in it. Its purpose is to be an unprivileged account for the HTTP daemon to use. It has read-only access to the web server's document root
Quote:
. As has been stated, the web server only needs to be able to read those to serve them...it does not need write access to them.
But I generally develop on my own computer (php scripts and such) then upload to server via winSCP. And then when php (and some data files) executed by apache's www-data user, and that user cannot read from my WinScp user which is "Myuser". So even if I chown that php scripts to www-data, they are not writeble as www-data only has read access.

Also, if I remove my user from www-data group, this time I cannot delete or modify files thru SCP/sftp.

Quote:
Let us know and we can provide more specific advice and tips.
this is my current group structure:

sudo:x:22:MyUser
MyUser:x:1000:www-data
www-data:x:31:MyUser

So, I must remove MyUser from group 1000. but is it a problem if I keep MyUser in www-data group?

this is exactly what I was looking for. Thank you very much.


edit:
I follow the blog post. But my problem persists:

I think my problem lies in the fact that my scripts uses too much file operations. There are countless php scripts that modify files on the web root, I have to cherry pick all those files to give them proper access. And when scripts create a new file which belongs to www-data, I cannot modify them with SCP, I need to log in, sudo, set proper access privileges to those files and exit. I think I need a plan or change my view of how I access those files as server admin.

Last edited by ref-x; 04-23-2018 at 05:55 AM.
 
Old 04-23-2018, 05:53 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,330
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by ref-x View Post

I think my problem lies in the fact that my scripts uses too much file operations. There are countless php scripts that modify files on the web root, I have to cherry pick all those files to give them proper access. And when scripts create a new file which belongs to www-data, I need to log in, sudo, set proper access privileges to those files and exit. I think I need a plan or change my view of how I access those files as server admin.
If you can, it would be a Very Good Idea to separate the directories into ones that handle only data and ones that contain only scripts or anything script-like. So that way you won't have to mix functionality. You can keep the files with scripts read-only, from the HTTP daemon's perspective, in read-only directories and allow things to be written in the data directories where nothing can run. The principle there is things can be either executable or writable but not both: W^X The intention is that in case of a successful breach an unwelcome visitor cannot write their own scripts and run them.

So a plan is needed. It might take a bit of work on a whiteboard or a large piece of paper or two. Remember, a week of coding can save several hours of planning.
 
1 members found this post helpful.
Old 04-23-2018, 06:40 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
you need a workspace, where you edit your files and an "install" area where they are in use. And you need only one script which will copy those files from workspace (and obviously set permissions).
 
1 members found this post helpful.
Old 04-23-2018, 08:31 AM   #10
ref-x
LQ Newbie
 
Registered: Apr 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
If you can, it would be a Very Good Idea to separate the directories into ones that handle only data and ones that contain only scripts or anything script-like. So that way you won't have to mix functionality. You can keep the files with scripts read-only, from the HTTP daemon's perspective, in read-only directories and allow things to be written in the data directories where nothing can run. The principle there is things can be either executable or writable but not both: W^X The intention is that in case of a successful breach an unwelcome visitor cannot write their own scripts and run them.

So a plan is needed. It might take a bit of work on a whiteboard or a large piece of paper or two. Remember, a week of coding can save several hours of planning.
Ok, now I am more aware of my problem. I'll take look of scripts that create or modify files and plan accordingly.

I'll be asking more questions in the future. Thank you all.
 
Old 04-23-2018, 09:30 AM   #11
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Rather than create a blank file and retype everything, you can change the owner of the file
Code:
$ sudo chown user:group filename
or of a directory and its contents
Code:
$ sudo chown -R user:group directory
 
Old 04-23-2018, 12:41 PM   #12
mpapet
Member
 
Registered: Nov 2003
Location: Los Angeles
Distribution: debian
Posts: 548

Rep: Reputation: 72
Quote:
Originally Posted by ref-x View Post
So, I must remove MyUser from group 1000. but is it a problem if I keep MyUser in www-data group?
No! GID 1000 is the first non-system user on the system. Don't remove your user from that group.

Remove your user account from the www-data group. And then remove the www-data group from your user account group. Those are two different commands.

Last edited by mpapet; 04-23-2018 at 12:42 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Linux File Permissions, Groups, and Users LXer Syndicated Linux News 1 11-04-2010 04:37 AM
How to setup file permissions for multiple groups/users that use Windows AND Linux unassassinable Linux - Security 4 11-02-2010 08:00 PM
LXer: Autonomously Generating An Ideal Kernel Configuration LXer Syndicated Linux News 0 04-10-2010 09:41 PM
Ideal hardware configuration for Puppy vvkozmenko Puppy 19 11-29-2006 01:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration