4 Answers
4

Not globaly, no. You could however, restrict access to /usr/bin/w and put an alternative file as /usr/local/bin/w. That could be a simply script that calls the original tool with parameters and filter arguments, and a setuid statement.

The information used by w and who is kept in /var/run/utmp or /run/utmp (sometimes /etc/utmp in old systems). You need to restrict read access to that file.

(Don't bother with removing the commands; if you leave utmp readable, anyone can get the addresses with a two-minute script.)

However, this will not hide other users' login names. For this, you have to prevent ordinary users from seeing all processes – which can only be done with such kernel patches as grsec. (If you are going to grant access to random, untrusted people, grsec may be a good idea anyway.)

Second, if you're going for privacy, you would have to prevent users from listing all system accounts; this cannot be done with traditional Unix /etc/passwd, since restricting read access to it would break many things. Instead, you would need a separate user directory, such as sssd, LDAP, perhaps some SQL database.

By default the FROM field in w is only shown to root and not to 'regular' users. Assuming your users are on regular accounts, they shouldn't see the details you are seeing.
If your compiled version does do this, then use the -f switch to suppress the information:

w -f

You could add this as an alias for w on user profiles (~/.bash_profile):

This is incorrect for the default Linux procpsw/who, nor the one from BSDs. They show all fields to everyone, since all data is stored in a single world-readable utmp file anyway. (On some systems, w needs the -f option to show the field, on others - to hide it, but that's merely a compile-time preference.)
–
grawityDec 28 '11 at 12:54

Unfortunately this does not seem to be the case with CentOS 5. Even regular users see the from field.
–
jamesDec 28 '11 at 12:58

You could think about giving your users a restricted shell and set up a special bin-directory for them, where you have wrapped or special versions of "w" and "who". See the bash manpage section RESTRICTED SHELL.