How to protect a file under a writable directory [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I am coming across some problem with file permission and acl.
I've got a writable directory name "dir" with the permission 777 (dir rwxrwxrwx)
Under dir I create a file tmp.txt (dir/tmp.txt)
I was wondering how can I stop other/group members to edit/delete the file while not changing the permission of "dir". Everyone is free take any action as they like to the other file/directory under "dir".
I was wondering maybe "setfacl" or what.

Whoever owns the directory can delete the files within it, even if they are owned by root.
There are two ways to get you to almost where you want.
Idea 1 - Sticky Bit
$ ls -ld /tmp
drwxrwxrwt 33 root root 1020 2020-03-14 14:06 /tmp/
This is the common permissions for Unix /tmp directory. That t there at the end of the permissions denotes the sticky bit, you can set it by running:
chmod +t /tmp
The sticky bit says that even though everyone has write permission on the directory, the only ones who can delete a file under that directory are root, the directory owner, and the file's owner.
Idea 2 - Extra Directory
A directory cannot be deleted if it's not empty. If you put your files in a directory that's owned by you, where only you (and root) can delete files, then nobody else can delete it:
root#playground# tree -up
.
`-- [drwxrwxrwx root ] box
|-- [-rw-r--r-- test1 ] f1
`-- [drwxr-xr-x test2 ] hello
`-- [-rw-r--r-- test2 ] f2
2 directories, 2 files
root#playground# su test1
test1#playground$ rm box/hello
rm: cannot remove ‘box/hello’: Is a directory
test1#playground$ rm -rf box/hello/
rm: cannot remove ‘box/hello/f2’: Permission denied

Related

Creating a file inside 0766 directory fails [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
Created a directory as root and changed its permissions to 0766:
drwxrw-rw- 2 root root 4096 Aug 2 13:33 test/
When running touch test/test.txt as a user, I get error: touch: cannot touch 'test/test.txt': Permission denied.
$getfacl /test
getfacl: Removing leading '/' from absolute path names
# file: test
# owner: root
# group: root
user::rwx
group::rw-
other::rw-
The directory is set with write permission to all users, what am I missing?
For directories the bits of the access rights have a different meaning than for files:
x means that files inside the directory may be accessed.
r means that you can list the names of the files inside directory. If r is set but x is not set, ls can list the names of the files and sub-directories inside the directory; however, ls cannot show you more information if x is not set; not even if some file it is a regular file or a sub-directory.
w is required to rename or to delete files or to create files or sub-directories inside the directory. However, w has no effect if x is not set!
0766 directory
Because x is not set for group and others, this is the same as a 0744 directory:
Other users may list the names of files and sub-directories inside the directory, but they cannot do more: They cannot even see if some file inside the directory is a regular file or a sub-directory.
You might have an Access Control List (ACL), which permits the access to your folder.
I don't know very much about those lists, but this link should explain them https://www.redhat.com/sysadmin/linux-access-control-lists
You can view the ACL using the getfacl command

Why is the 'mv' command not working when moving a file up multiple levels [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Operating system: SLES12 VM
So I start off in a directory:
DirA: /home/user/testA/testB
My goal is to move a file from this directory to a directory given by
DirB_rel: /home/user/testA/testB/../../deliverables/rpm/SOURCE
Note: testA is a symlink which is not included in DirB_abs
Which, when I cd to it, gives a pwd of
DirB_abs:/home/user/deliverables/rpm/SOURCE
The problem is, when I try move a file using mv (have tried tar.gz and .txt) from DirA to DirB_rel, the file is deleted from original location as expected, but it does not appear at new location and is therefore lost.
E.g. mv testFile.txt DirB_rel -> File disappears
However, when I use the absolute path for directory B, mv works correctly.
E.g. mv testFile.txt DirB_abs -> Success
Any idea whats going on here?
Thanks!
The problem is with the symlink. When you do user/testA/testB/../../ and testA is asymlink, you wont go back to user, but to the parent directory of the directory testA links to
the mv command will reference the directory you are currently in and not from where the file is. So if we are in home ~/ and want to move ~/A/file to ~/B/file you use mv as follows:
mv A/file B/
Note that if you use this
mv A/file ../B/
the command will look for B in /home/B and not ~/B since we are in the ~/ directory issuing the command.

How to turn a directory into a hidden directory [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have a directory /f/ssh which I would like to turn into /f/.ssh. I'm working with git-bash on win7 I've tried:
/f
$ mv /ssh /.ssh
mv: cannot stat `/ssh': No such file or directory
/f
$ mv ssh .ssh
mv: cannot move `ssh' to `.ssh/ssh'
But its not working. How can I make this happen ?
You probably want your second example (current working directory) and not root (/).
$ mv ssh .ssh
mv: cannot move `ssh' to `.ssh/ssh'
What this is saying is there is already a folder called ".ssh" in your current working directory.
By calling that command again it's also saying you don't have access to move "ssh" into the already existing ".ssh" folder.
Try an ls -al to list all current files/folders in the directory, including hidden.

Will the program installed in a folder function properly if I remove the write permission in linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have a user account on a cluster( a server), and can only install program like python on the home folder. In case I might accidentally delete the bin, lib, share,include folders coming with the installation of python on the home folder. I change the permissions of the above folder like this
chmod -w folder
but I am worried when the program need to write/delete some files of the folders, it might not function because the removal of write permission. Am I right? or I the run, including write files in the folder, of a program have permissions different than the permission of user.
BTW, is there a way to hide the folders without changing the names?
Wouldn't this stop python from running all together? For example:
$ cd ~
$ mkdir -p python/bin/
$ echo "echo 'hi'" > python/bin/python
$ python/bin/python
hi
$ chmod -x python
$ python/bin/python
bash: python/bin/python: Permission denied
As for your second question, no, there is no other way to selectively hide one folder without changing the name.
Edit: re-reading, I may have mis read what you were saying about the folders. You could always apply a "chmod -r folder" and nothing inside will be visable. This is not hiding it, just turning off permissions to view it.

What does the 'x' mean in rwx on a directory? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I got a testdir by mkdir testdir, and created a file in it by touch testdir/a.
drwxr-xr-x 2 jermaine jermaine 4096 Mar 12 22:57 testdir
If I remove the 'x' by chmod -x testdir
Then I won't be able to
cd testdir
touch testdir/b
ls -l testdir
cat testdir/a
So my question is why can't I list the file hierarchy under a directory with a 'r' but without an 'x'? What exactly does the 'x' mean on directory?
I knew some explanations like "x means entering the direcotry, you have to enter before read and write". But what does 'enter' mean? I really appreciate answers on inode or dentry level. Thanks a lot.
"Execute" is the traversal permission on a directory. It allows you to access files and folders within the directory.
If you can read a directory, you can list the contents.
If you can write a directory, you can make new files and folders within it.
If you can "execute" a directory, you can move through the hierarchy, even if you don't know what's inside.
When applying permissions to directories on Linux, the permission bits have different meanings than on regular files.
The write bit allows the affected user to create, rename, or delete files within the directory, and modify the directory's attributes
The read bit allows the affected user to list the files within the directory
The execute bit allows the affected user to enter the directory, and access files and directories inside
Execute permission on a directory means you can access files in that directory.
Check this link out for more information about Unix permissions:
http://www.cyberciti.biz/faq/how-linux-file-permissions-work/

Resources