In Linux, how can I identify if a binary file is set-user-ID?

Can I use ls -l?

closed as unclear what you're asking by jasonwryan, Archemar, Stephen Kitt, Anthon, John WH Smith Mar 26 '15 at 11:25

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What is the problem with ls -l? – michas Mar 26 '15 at 8:03
  • @michas I meant using ls -l? – Zhenxiao Hao Mar 26 '15 at 8:05
  • Sure you can use ls -l, why the doubt? – michas Mar 26 '15 at 8:09
  • @michas I was not sure. – Zhenxiao Hao Mar 26 '15 at 8:10

executing ls -l you will get something like:

-rwSr--r--   1 user user    8111573 Sep 26  2012 net-snmp.tar

where the S (can be also s) indicate this file have SUID set

S is set when you do not have execution flag set

s is set when you have execution flag set

  • 1
    In short: s = x + setuid, S = setuid without x. (setuid+x gets the more "normal" character because it's more common) – immibis Mar 26 '15 at 8:05

Either manually look at the file with ls -l filename, or from a script you can use

[ -u filename ] && echo SUID-bit is set

See also man bash:

   -u file
          True  if  file  exists  and its set-user-id bit is set.

See also info ls:

 The file mode bits listed are similar to symbolic mode
 specifications (*note Symbolic Modes::).  But ‘ls’ combines
 multiple bits into the third character of each set of permissions
 as follows:

      If the set-user-ID or set-group-ID bit and the corresponding
      executable bit are both set.

      If the set-user-ID or set-group-ID bit is set but the
      corresponding executable bit is not set.

Not the answer you're looking for? Browse other questions tagged or ask your own question.