LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 09-30-2005, 05:15 PM   #1
markraem
Member
 
Registered: Nov 2003
Posts: 82

Rep: Reputation: 15
I accidentally removed the netstat command !


I accidentally removed the netstat command from /usr/bin on solaris 8.

From another sol 8 system I transfered the netstat executable back to /usr/bin.

However, when I do :

ls -al

on the machine containing the good netstat i get following result :
-r-xr-sr-x 1 root sys 55180 Jan 6 2004 netstat

I noticed 2 things :
==================
first the strange execeutableflag = s (probably stand for sys)

second the ownership sys in root sys

Now, on the system where I would like to restore the netstat bin, what commands shoudl i type to make executableflags and the ownerships match exaclty the same ?

can I simply use 'chown root:sys netstat' ?
but what about the execflags ?
I know r-x means 5 but how is r-sr represented ?

would it harm the system if I simply do
chmod 777 netstat
chown root:root netstat ?
 
Old 09-30-2005, 05:35 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
chmod <edit>2555</edit> netstat

BTW, that bit is called the "set group ID on execution" bit. What that means is no matter who executes that file and what group they live in (providing they have permissions to execute of course) it gets executed with a gid of the owning group. Typically when you execute a file it gets executed with the gid of your users main group.

Last edited by jtshaw; 09-30-2005 at 08:00 PM.
 
Old 09-30-2005, 05:39 PM   #3
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
I don't think you've actually removed netstat, but a link to the executable. Try running:

find / -name netstat

Once found, make a link of it to your /usr/bin, like this:

ln -s /<whereever netstat is> /usr/bin/netstat

Permission 777 is a bad idea, because that gives full read. write and execute permissions for any user on the system. Usually, users should be able to read and execute, but not write to this kind of files (exactly to avoid deletion or modification).

In Unix, those 777 are actually octal numbers (base 2). as an example, let's suppose we have a file called "test" on your /export/home/markraem. Typing ls -l would say something like this (I'm not on Solaris right now, so I can't test this):

ls -l test
-rwxr-xr-x


Let's brake it into pieces. The first character, the dash (-) tells that this file, is actually a file. If it was a directory, it should be a "d" instead. The next three characters are permissions set to the owner (rwx), where r=read, w=write and x=execute. As I said, those numbers has a base two, so:

4 2 1
r w x


4 + 2 +1 = 7. That grants full read, write and execute permissions to the owner. Let's take the next three bits and analize them. The next three characters are values set for the group (r-x), where r=read, x=execute. With base 2, we have:

4 2 1
r - x


That would be 4 + 0 + 1 = 5. 5 grants read and execute permissions. To be able to execute a file, users must also be able to read them. The next three bits are permissions set to all other users. Since others, in this case, has the same symbolic permissions as the group, it's also 5. So this file has a permission of 755. 655 is a pretty common setting for a file. Directories are a bit different though, but still follow the same rules.

In Solaris, some files are read only (r--r--r--), as example, we have the file /etc/passwd, which stores information for every user, including their preferred shell and default home directories. Since the root is the owner of that file, he is the only one capable of changing it's permission, in the case he needs to modify that file (say, remove an user password or change the default shell). Thus, a r--r--r-- file has a permission of 444.

You can also use symbolic values instead of octal in Unix. For example, chmod +x file would make a file, an executable file.

Sorry for the lecture, I got a little carried on . Well, try finding the netstat path and link to your /usr/bin

Regards!

Last edited by Mega Man X; 04-10-2006 at 03:58 PM.
 
Old 09-30-2005, 07:53 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Megaman forgot about the first byte....

The 2 in my reply means "set group id on execution". There is also a "set user id on execution" (4) and a "sticky bit" (1).

4 2 1
S S T

For more information man chmod.

Last edited by jtshaw; 09-30-2005 at 07:57 PM.
 
Old 09-30-2005, 07:59 PM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Oh ya.. I'm an idiot I ment to say, chmod 2555 netstat is what you want

Code:
johnshaw@Quaqmire-OSX ~ $ chmod 2555 testfile 
johnshaw@Quaqmire-OSX ~ $ ls -la testfile 
-r-xr-sr-x   1 johnshaw  johnshaw  0 Aug 17 23:38 testfile

Last edited by jtshaw; 09-30-2005 at 08:00 PM.
 
Old 10-01-2005, 04:31 AM   #6
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Nice post jtshaw. I did not know that
 
Old 10-03-2005, 10:18 AM   #7
markraem
Member
 
Registered: Nov 2003
Posts: 82

Original Poster
Rep: Reputation: 15
Jtshaw :

thanks for your reply :



After download of netstat I typed :

chmod 2555 netstat

and

chown root:sys netstat.

rebooted the machie.

This works great
 
  


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
accidentally removed /dev/cdrom verbose Linux - General 18 10-26-2005 03:44 PM
'Accidentally' removed XFree86-libs, how can I bring back the desktop? freddan Fedora 3 03-22-2004 08:56 AM
Netstat command scottpioso Linux - Networking 14 09-06-2003 10:06 AM
newbie - removed partition accidentally kristalchimera Debian 6 07-12-2003 11:36 PM
I accidentally removed lilo from my bootsector. Grafbak Linux - Newbie 2 06-20-2003 03:22 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

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