In ls, how can I remove bg color for sticky bit

4

How can I remove the background color for the sticky bit. LSCOLORS looks like this export LSCOLORS="Gxfxcxdxbxegedabagacad"

Using oh-my-zsh

Edit: As suggested I tested LSCOLORS="" ls but the colors are still there.

enter image description here

grm

Posted 2011-04-19T10:14:37.263

Reputation: 2 164

What happens with the command LSCOLORS="" ls -ltr? – mpez0 – 2011-04-19T11:21:54.870

You need LS_COLORS=, not LSCOLORS=. See man dircolors. – Mikel – 2011-04-20T22:41:03.843

Answers

2

Your example doesn't show the sticky bit, it shows setgid. (sticky is chmod +t, you have chmod g+s.)

Are you sure you need that? It seems wrong to me.

Setgid on a directory means that files created in that directory will have the group from the directory, not the user's primary group, so that's quite useful.

But setgid on a normal, non-executable file doesn't do anything useful.

I would suggest removing setgid from all files (but leave it on directories) like this:

find . -type f -exec chmod g-s {} \;

Or you could force a set of known permissions on files and directories using:

find . \( -type d -exec chmod g=rwsx {} \; \) -o \( -type f -exec chmod g=rw {} \; \)

And next time, rather than using chmod -R g+s or find -exec chmod g+s {} \;, do this:

find . -type d -exec chmod g+s {} \;

so that it only affects the directories.


Background

ls colors setgid files because if the file is also executable, it would run with extra permissions.

I think the idea is that the yellow and black highlighting is meant to make you look carefully at them, to make sure they are the ones you expect, and not some new file that was installed by a malicious user or a rootkit or something.

Run

find /usr -perm -2000

to see some examples of programs that use those permissions.

On my system it lists

/usr/bin/wall
/usr/bin/chage
/usr/bin/expiry
...

For example, the r-s on /usr/bin/wall

$ ls -l /usr/bin/wall
-rwxr-sr-x 1 root tty 9888 2008-04-29 11:57 /usr/bin/wall

means that the wall program can write output to any user's tty, even if it's not running as root.


If after all that, you still really want to change the colors, try something like this:

LS_COLORS=${LS_COLORS/sg=30;43:/sg=00:}

Where you put it depends on your setup, but at the end of ~/.zshrc should do it.

For some reason, removing the sg (setgid) entry makes it use the default colors, rather than no special colors.

Mikel

Posted 2011-04-19T10:14:37.263

Reputation: 7 890

Yes, I meant the setgid bit and not the sticky bit. I use the g+s with umask to allow multiple users to edit files that are owned by www-data. I still don't like the color and I really don't think ls is the right tool to hunt down rootkits. – grm – 2011-04-21T22:04:15.423

You don't need g+s on the files, you need g+w on the files and g+ws on the directories. – Mikel – 2011-04-22T00:38:23.750

Yes, you are right. Will correct that. Thanks! – grm – 2011-04-22T07:33:08.217