LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 10-25-2008, 07:32 AM   #1
Nzo
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Rep: Reputation: 0
openSSH, user permissions for PHP files.


Is it possible to allow a user to have execute permissions, but then block them from reading, writing, moving and copying that same file?

Thanks.

Last edited by Nzo; 10-25-2008 at 09:20 AM.
 
Old 10-25-2008, 09:21 AM   #2
Nzo
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Original Poster
Rep: Reputation: 0
anyone at all?
 
Old 10-25-2008, 10:54 AM   #3
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
well you could do chmod 111 filename, that'll prevent most of what you want (read, copy), writing is sort of blocked, moving and deleting (along with writing) are driven more by the directory permissions then file permissions. The reason I say writing is sort of blocked is that, while the file itself wouldn't be writable, it could be replaced with one that is via a move or delete.
 
Old 10-25-2008, 12:02 PM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by estabroo View Post
well you could do chmod 111 filename, that'll prevent most of what you want (read, copy), writing is sort of blocked, moving and deleting (along with writing) are driven more by the directory permissions then file permissions. The reason I say writing is sort of blocked is that, while the file itself wouldn't be writable, it could be replaced with one that is via a move or delete.
That would be the way that I do it...

Also you can look at setfacl

man setfacl for more info...

-C
 
Old 10-25-2008, 05:21 PM   #5
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Also you can make it immutable with chattr as root. chattr +i filename
This will probably do exactly what you want.

excerpt from chatter manpage:
A file with the `i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be
written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.
 
Old 10-26-2008, 12:55 PM   #6
Nzo
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Original Poster
Rep: Reputation: 0
I tried chmod 111 file.php, so the permissions are like this:
Code:
---x--x--x
then I try to execute:
Code:
php file.php
and i get
Code:
Could not open input file: file.php
I tried
Code:
chattr +i file.php
but the script was still readable, but uneditable. I want to be able to prevent users reading the file, but allow them to execute it.

I also looked at setfacl, doesnt this do the same as chmod?

Thanks for your suggestions!

Last edited by Nzo; 10-26-2008 at 12:58 PM.
 
Old 10-26-2008, 01:10 PM   #7
Nzo
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Original Poster
Rep: Reputation: 0
Another way I could get round this, is give the user read and execute permissions (-r-x) so that the file will run, then only allow them to use the command: "php file.php".

That way they wont be able to "vi file.php" and read the file contents, and also wont be able to use commands to copy or move the file to a different directory or computer.

How can I prevent all commands apart from "php file.php" for a user?
 
Old 10-26-2008, 03:15 PM   #8
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by Nzo View Post
I also looked at setfacl, doesnt this do the same as chmod?

Thanks for your suggestions!
Not exactly....it's more granular than just the chmod/chown/chgrp commands...

You can set the owner and group to be you (and your group) but give perms to others...

Example

Code:
root@host# chmod 550 file.php
root@host# chown me:me file.php
root@host# setfacl -m group:<groupname>:--x file.php

OR

root@host# serfacl -m user:<username>:--x file.php
Where <groupname> is the name of the group and <username> is the name of the user.
 
Old 10-26-2008, 05:00 PM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
A file needs to be read to be able to be executed. You can set the immutable bit.

What are the permissions of the directory the file is in? That will determine whether the file can be deleted. If the user has write permissions on the directory, (such as in /tmp) then set the "sticky" bit on the directory. Deleting and saving files in a directory is a write operation on the directory. The sticky bit will prevent one user from deleting files owned by other users (except for the root user).

Using SELinux, you can protect a file even from root, unless the root user explicitly modifies the security attributes of the file.

You can't prevent an executable (permitted) file from being read, and thus copied. The only way around this, that I can think of, is to have it executed by proxy. E.G. client/server. Maybe you could have a stub program that assumes the euid or egid of the caller (for permissions) and executes it as if it were the user. The target program would be in a directory inaccessible by the user.

Maybe you could explain what this file is and why you don't want it copied but want it executed by a user. If you have a script that has username/password info in it, then your problem isn't disallowing the reading of the file. World readible scripts should not have authentication information in them. For example, never have "username" & "password" options in /etc/fstab. Use the "credentials" option instead, referencing a file that only root can read.

Last edited by jschiwal; 10-26-2008 at 05:13 PM.
 
Old 10-26-2008, 10:07 PM   #10
Nzo
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Original Poster
Rep: Reputation: 0
ok I understand setfacl a bit more now.

The reason I want to keep the file unreadable but allow access is because I have a hosted web server, which will receive data, then connect via a PHP script using SSH to another server, and send the data in variables by running a command like so:
Code:
php file.php vone vtwo
I dont want people copying or hacking my processing PHP code!

So if anybody with access to the hosted web server takes my ssh username and password, connects to my remote server via SSH, they can do whatever they want as that user.

Other ways I thought about sending the data was in html form posts, but i dont have a SSL certificate (the data needs to be safe). I could encrypt at one end and decrypt at the other using the built in PHP functions...

I also want to prevent random people from sending my remote server fake data to process, but I think ill check which IP the data is coming from in my PHP script.

Any ideas on other ways I can get data server-server securely + quickly using PHP/linux/ssh?
 
Old 10-27-2008, 08:27 AM   #11
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
You could always make a suid C wrapper that executes your php. This would allow you to make the php have permissions that make it unreadable by the user but still executable.

Setting 111 permissions for compiled programs works fine, you don't need read permission to execute them. I'd forgotten that scripts need to be readable since they get loaded by an interpreter.
 
  


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
Download files to windows from linux using Openssh ZAMO Linux - General 3 06-02-2008 06:12 AM
Forcing User Permissions on a Directory (and all subdirectories and files in the dir) hevfuture Linux - Newbie 3 03-26-2008 12:39 PM
openssh user configuration mohtasham1983 Linux - Server 8 05-03-2007 04:43 AM
user permissions to create files and directories ringding Linux - Security 3 09-07-2006 04:34 PM
Limting openssh port forwarding per user onaias Linux - Security 4 01-10-2004 05:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:55 AM.

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