Linux Configuration Commands

Operating as root: (System Administrator)

If you are planning to administer the system, one would login as root to perform the tasks. In many instances one would be logged in as a user and wish to perform some “root” sys-admin tasks. Here is how:

  • Switch user account to root: Shell/command mode:
    su -
    and then you will be prompted to enter the root password.
  • GUI mode:
    • Allow console to be accessed by another user from same system:
      xhost +localhost
    • Switch user and then you will be prompted to enter the root password:
      su -
    • Set environment variable for GUI sessions so that display used is local display. (Remember X-windows is a network enables windowing system)
      export DISPLAY=:0.0
    • Launch GUI application.

Note: The su command was issued with a trailing “-” which means that the login process will follow the login steps of the user and will execute its profiles. Since no user id was given, the default is root user. This all would be equivalent to: su - root

Some systems may be configured so that only the switch user (su) command may be required without all of the X-window configuration.

Hard Drive Linux Commands:

df -k report filesystem disk space usage. (-k reports in Kbytes)
du -sh Calculates file space usage for a given directory. (and everything under it) (-s option summarizes)
mount Displays all mounted devices, their mount point, filesystem, and access. Used with command line arguments to mount file system.
cat /proc/filesystems Display filesystems currently in use.
cat /proc/mounts Display mounted filesystems currently in use.
showmount Displays mount info for NFS filesystems.
cat /proc/swaps Displays swap partition(s) size, type and quantity used.
cat /proc/ide/hda/any-file Displays disk information held by kernel.

IDE drives are referred to as hda for the first drive, hdb for the second etc…

Note: SCSI disks are labeled /dev/sda, sdb, etc…

Linux IDE naming conventions:

Device Description Configuration
/dev/hda 1st (Primary) IDE controller Master
/dev/hdb 1st (Primary) IDE controller Slave
/dev/hdc 2nd (Secondary) IDE controller Master
/dev/hdd 2nd (Secondary) IDE controller Slave
User Info:


who Displays currently logged in users.
Use who -uH for idle time and terminal info.
users Show all users logged in.
w Displays currently logged in users and processes they are running.
whoami Displays user id.
groups Display groups you are part of.
Use groups user-id to display groups for a given user.
set Display all environment variables in your current environment.
id Display user and all group ids.
Use id user-id to display info for another user id.
last Listing of most recent logins by users. Show where from, date and time of login (ftp, ssh, …) Also see lastlog command.
Show last 100 logins: last -100
history Shell command to display previously entered commands.


User Greetings:

The greeting messages and login displays are all customizable.

Type of greeting File
Telnet pre-login Text: File containing text: /etc/issue
Ssh pre-login Text: /etc/ssh/sshd_config
Specify text file: Banner /etc/issue
vsftpd Login Text: vsftpd config file: /etc/vsftpd/vsftpd.conf
Set text greeting: ftpd_banner=Put welcome greeting here
Post login text message:
(message of the day)
Default is blank.
GDM graphical login display: /etc/X11/gdm/gdm.conf (or /etc/gdm/gdm.conf)
Set image: DefaultFace=/path/file.png
Set logo: Logo=/path/file.png
Set background: BackgroundImage=/path/file.png
System log files:
    /var/log/messages   - system messages
            /secure     - Logging by PAM of network access attempts
            /dmesg      - Log of system boot. Also see command dmesg
            /boot.log   - Log of system init process
            /xferlog.1  - File transfer log
            /lastlog    - Requires the use of the lastlog command to examine contents
            /maillog    - log from sendmail daemon


Using the Linux / UNIX find command:

Find man page

Form of command: find path operators


  • Search and list all files from current directory and down for the string ABC:
    find ./ -name "*" -exec grep -H ABC {} \;
    find ./ -type f -print | xargs grep -H "ABC" /dev/null
    egrep -r ABC *
  • Find all files of a given type from current directory on down:
    find ./ -name "*.conf" -print
  • Find all user files larger than 5Mb:
    find /home -size +5000000c -print
  • Find all files owned by a user (defined by user id number. see /etc/passwd) on the system: (could take a very long time)
    find / -user 501 -print
  • Find all files created or updated in the last five minutes: (Great for finding effects of make install)
    find / -cmin -5
  • Find all users in group 20 and change them to group 102: (execute as root)
    find / -group 20 -exec chown :102 {} \;
  • Find all suid and setgid executables:
    find / \( -perm -4000 -o -perm -2000 \) -type f -exec ls -ldb {} \; 
    find / -type f -perm +6000 -lsNote: suid executable binaries are programs which switch to root privileges to perform their tasks. These are created by applying a “sticky” bit: chmod +s. These programs should be watched as they are often the first point of entry for hackers. Thus it is prudent to run this command and remove the “sticky” bits from executables which either won’t be used or are not required by users. chmod -s filename
  • Find all world writable directories:
    find / -perm -0002 -type d -print
  • Find all world writable files:
    find / -perm -0002 -type f -print
    find / -perm -2 ! -type l -ls
  • Find files with no user:
    find / -nouser -o -nogroup -print
  • Find files modified in the last two days:
    find / -mtime 2 -o -ctime 2
  • Compare two drives to see if all files are identical:
    find / -path /proc -prune -o -path /new-disk -prune -o -xtype f -exec cmp {} /new-disk{} \;

Partial list of find directives:



-name Find files whose name matches given pattern
-print Display path of matching files
-user Searches for files belonging to a specific user
-exec command {} \; Execute Unix/Linux command for each matching file.
-atime (+t,-t,t) Find files accessed more that +t days ago, less than -t or precisely t days ago.
-ctime (+t,-t,t) Find files changed …
-perm Find files set with specified permissions.
-type Locate files of a specified type:

  • c: character device files
  • b: blocked device
  • d: directories
  • p: pipes
  • l: symbolic links
  • s: sockets
  • f: regular files
-size n Find file size is larger than “n” 512-byte blocks (default) or specify a different measurement by using the specified letter following “n”:

  • nb: bytes
  • nc: bytes
  • nk: kilobytes
  • nw: 2-byte words
File Information/Status/Ownership/Security:
ls List directory contents. List file information
chmod Change file access permissions
chmod ugo+rwx file-name :Change file security so that the user, group and all others have read, write and execute privileges.
chmod go-wx file-name :Remove file access so that the group and all others have write and execute privileges revoked/removed.
chown Change file owner and group
chown root.root file-name :Make file owned by root. Group assignment is also root.
fuser Identify processes using files or sockets
If you ever get the message: error: cannot get exclusive lock
then you may need to kill a process that has the file locked. Either terminate the process through the application interface or using the fuser command: fuser -k file-name
file Identify file type.
file file-name
Uses /usr/share/magic/usr/share/magic.mime for file signatures to identify file type. The file extension is NOT used.


My Reference notes all credits to http://www.yolinux.com/TUTORIALS/

Leave a Reply

Your email address will not be published. Required fields are marked *