LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 09-12-2012, 02:39 PM   #1
Obscurious
LQ Newbie
 
Registered: Jun 2009
Distribution: Debian, RHEL, FreeBSD
Posts: 17

Rep: Reputation: 0
Using the Recursive Switche in Commands


I recently ran into a permission problem wherein a user, belonging to the group owning the files, was not able to write. Since the write operation the user wanted to perform was a complicated Git command it was not a matter of checking one file's permissions. I simply issued


Code:
sudo chown -R git:git /home/git/projectX
sudo chmod -R g+w /home/git/projectX
The permission problem still persisted. Digging around I found that a directory

Code:
/home/git/projectX/.git/objects
was not group writable even after issuing the above commands.

Is my understanding of the -R switch wrong? The -R works in other cases on hidden directory and files. Can anyone offer some insight, please and thanks.
 
Old 09-12-2012, 03:02 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,093

Rep: Reputation: 2301Reputation: 2301Reputation: 2301Reputation: 2301Reputation: 2301Reputation: 2301Reputation: 2301Reputation: 2301Reputation: 2301Reputation: 2301Reputation: 2301
sudo loses the permissions war with root on occasion. Su & password do also.

su - is better.
 
1 members found this post helpful.
Old 09-12-2012, 03:15 PM   #3
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
If I create a simple directory tree, and in that tree, include a directory starting with dot, chmod -R g+w changes the group write permission just fine, on the system I'm using.

Are you saying that if you look at the permissions on /home/git/projectX/.git/objects the group write bit is not set?

Or are you instead saying that when some complicated Git command is run, there are error messages?

More complete details on the situation would be helpful.

Without them, we can only guess, or try to provide rather general ideas.

Sometimes there can be issues with sudo instead of su.

Some implementations of chmod process symbolic links differently, depending on whether the link was specified on the command line or encountered recursively.
Also, sometimes there can effectively be an interaction between mode bits.

Some implementations of chmod accept a -v option which causes the command to provide a verbose description for every change it makes, or does not make.
If your chmod has that option, you could try that to see if it tells you it will not change the group write bit in some situation.

Some commands run setuid/setgid and so if the issue is error messages from some Git command, or some other command which might be involved in the more complicated situation which you mentioned in passing, then the way in which permissions are being used might be more complicated that you originally expected.

HTH.
 
1 members found this post helpful.
Old 09-12-2012, 03:53 PM   #4
Obscurious
LQ Newbie
 
Registered: Jun 2009
Distribution: Debian, RHEL, FreeBSD
Posts: 17

Original Poster
Rep: Reputation: 0
I was running as root, i.e. sudo -s.
After running chmod -R g+w /home/git/projectX the directory /home/git/projectX/.git/objects still did not have the group write bit set.
Git is abstracted from this scenario, it only informed me of permission problems.
Here is the command line output from my problem:

Code:
$ sudo -s
# cd /home/git/projectX
# ls -la
-rw-rw-r--  1 git git  996 2012-07-06 10:36 COPYRIGHT.txt
-rw-rw-r--  1 git git  720 2012-07-06 10:36 cron.php
drwxrwsr-x  8 git git 4.0K 2012-08-27 16:08 .git/

# chmod -R g+w *
# ls -la .git
drwxr--r-x 190 git git 4.0K 2012-09-07 10:43 objects/
-rw-r--r--   1 git git   41 2012-08-27 16:08 ORIG_HEAD
-rw-rw-r--   1 git git   94 2012-07-06 10:36 packed-refs

#ls -la .git/objects
drwxr--r-x 2 root    git 4.0K 2012-09-04 12:21 00/
drwxr--r-x 2 root    git 4.0K 2012-09-04 12:35 01/
drwxr--r-x 2 root    git 4.0K 2012-09-04 12:21 02/
So you can see objects and the contents of objects did not get updated.

Running a clean test, using Kakaka's suggestion of the -v option we have:

Code:
$ sudo -s
# cd /home/obscurious
# mkdir -p tmp/.hidden
# touch tmp/.hidden/testfile
# ls -la tmp/.hidden/testfile
-rw-rw-r-- 1 root root 0 2012-09-12 13:27 testfile
# chmod -Rv g+x tmp
mode of `tmp' changed to 0775 (rwxrwxr-x)
mode of `tmp/.hid' retained as 0775 (rwxrwxr-x)
mode of `tmp/.hid/testfile' changed to 0674 (rw-rwxr--)
# ls -la tmp/.hid
-rw-rw-r-- 1 root    root       0 2012-09-12 13:27 testfile
Which worked as expected and did not reproduce the problem described above. I hope this is more clear. This is an up-to-date ubuntu server 12.04, running bash.
 
Old 09-12-2012, 04:06 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by Obscurious View Post
Code:
mode of `tmp/.hid/testfile' changed to 0674 (rw-rwxr--)
# ls -la tmp/.hid
-rw-rw-r-- 1 root    root       0 2012-09-12 13:27 testfile
That was expected? Or was that a typo?
 
Old 09-12-2012, 05:13 PM   #6
Obscurious
LQ Newbie
 
Registered: Jun 2009
Distribution: Debian, RHEL, FreeBSD
Posts: 17

Original Poster
Rep: Reputation: 0
Typo thanks for catching that.
 
Old 09-12-2012, 05:37 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,342

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
1. Try the -v option on the real thing
2. Its possible someone has used http://linux.die.net/man/1/chattr on that file; try http://linux.die.net/man/1/lsattr to check
 
Old 09-13-2012, 02:46 AM   #8
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Obscurious,

I had mentioned that sometimes mode bits effectively interact. Notice the s in the group section of the mode bits from this line of output you posted:

Code:
drwxrwsr-x  8 git git 4.0K 2012-08-27 16:08 .git/
If Git set that bit, then you may need to review Git's security model, because you might be effectively bypassing it by making the changes you are.

Depending on exactly how chmod is implemented in the kernel you are using, you may be able to remove the s by running:

Code:
chmod g-s .git
then if run purely as root ( that is, IF sudo -s in your environment is indeed equivalent to su - ) , the recursive chmod should likely behave as you expected.

But if Git set that bit and the original owner and group owner of the directories in the directory tree, ( possible bugs in Git not withstanding ) the bit probably shouldn't be changed, and the changes you are trying to make probably shouldn't be made.

Another possible command to investigate if there are still problems:

Code:
getfacl .git

Last edited by rigor; 09-13-2012 at 02:57 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Can you do recursive commands in smbclient? BrianK Linux - General 5 04-12-2012 08:08 AM
Linux equivalent commands for all Solaris commands Harry_Linux008 Linux - Newbie 4 08-22-2010 07:21 PM
Need help for Windows cmd commands into Linux terminal commands. windowsNilo Linux - Software 2 07-02-2008 06:26 PM
Need help for Windows cmd commands into Linux terminal commands. windowsNilo Linux - General 2 07-01-2008 06:53 AM
Suse Linux Commands For These Aix Commands? Vaskar Guha Linux - Software 2 12-19-2005 12:45 AM

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

All times are GMT -5. The time now is 11:17 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