Random linuxy things

I’m not sure how out of date some of these things might be as their source was initially written around about 2006. So basically what I’m saying is, take this with a pinch of salt – it might work, it might not and it might work but be very, very old-school.

APT

  • apt-get install packagename
  • apt-get remove packagename
  • apt-get purge packagename
  • apt-get update
  • apt-get upgrade
  • apt-get autoremove
  • apt-cache search searchterm
  • apt-cache search --names-only searchterm
  • apt-cache show packagename
  • apt-get clean

Building from source

Download a .tar.gz compressed tarball of the software source code that you want to install. You can examine the contents of the tarball using the following:

  • tar ztf filename.tar.gz | more

To extract the contents then use the following command which will extract it to the folder the tarball is in:

  • tar zxvf filename.tar.gz

To build the software first enter the extracted sourcecode directory and look at the readme – you can use cat/more/nano/gedit or whatever else you might prefer. Follow the instructions in the readme, but generally you’ll want to do the following.

  • cd sourcecodedirectory
  • ./configure
  • make
  • make install

./configure checks the system and looks for missing dependencies. It results in a Makefile which is need for the next step. make compiles the code to create an object file, whilst make install copies the compiled software to the relevant locations in the filesystem.

Security

Use GnuPG to encrypt and decrypt files with sensitive information.

Check log files in var/log to see if any unauthorised access has been attempted.

Use secure shell (ssh)

Instead of storing passwords in the /etc/passwd file which is readable by all, linux stores them in a shadow password file, /etc/shadow. use cat /etc/passwd or cat/etc/shadow to see how the contents differ. Use

  • sudo chage -l username

to find out details about a users password expiry.

Use the following to find the contents of the pluggable authentication modules

  • ls /etc/pam.d

To change the ownerships of files you need to be mindful of users and groups and which files belong to which.

  • chown user.group path/to/file
  • chgrp group filename

Common file permission numerical settings:

  • rw-r--r-- = 644
  • rwxrwxrwx = 777
  • rw-rw-rw- = 666

Use umask to print a number showing the current file creation mask. For root the mas is set to 022 and for normal users it is 002.

Use the following command to make sure there are no strange setuid programs. setuid applies to executable files and when enabled the file executes under the user ID of the file’s owner. So if owned by root, no matter who executes the program, it will run with root permissions.

  • find / -type f -perm +4000 -print

Servers

To find all the services that can be started and stopped and to find out how to change their status:

  • ls /etc/init.d
  • more /etc/init.d/README

TOP

The first line shows the current time, system uptime, number of users logged in, and 1,5,15 minute load averages

The second line list the total number of processes and their status

The third line shows CPU usage

The forth line shows how physical memory is being used, how much is free and buffers

The fifth line shows details of the swap memory

The table then lists the processes, process ID, username, priority, nice value, virtual memory usage, physical usage memory, process state, CPU usage, process uptime and the command that started the process.

VMSTAT

Use the following to view system usage averaged over 5 seconds and printed for 8 lines

  • vmstat 5 8

Disks

To see disk space statistics

  • df -h

To find disk space used by a specific directory

  • du -h /var/log

System information

  • cat /proc/cpuinfo
  • cat /proc/filesystems
  • cat /proc/loadavg
  • cat /proc/meminfo
  • cat /proc/modules
  • cat /proc/mounts
  • cat /proc/partitions
  • cat /proc/stat
  • cat /proc/version

AT

/etc/at.allow = configuration file listing the names of users who may submit jobs using the at command

/etc/at.deny = configuration file listing the names of users who may not submit jobs using the at command

at commands – use Ctrl-D to break out of the at program

  • at now
  • at now + 15 minutes
  • at now + 4 hours
  • at noon
  • at now next hour
  • at now next day
  • at 17:00 tomorrow
  • at 3:00 Dec 28, 2014

To see what jobs are queued

  • atq

To cancel a queued job (use the positional number of the process in the queue)

  • atrm 4

Recurring jobs should be planned using cron

Pop-up notifications

  • DISPLAY=:0 notify-send "Very Important Message Here"

System

Use env to see environment variables

Backups

You can use tar to help with backups:

  • tar zcvf /path/to/backup/to /path/to/backup/from

tar options:

  • c - creates new archive
  • f - specifies name of the archive file
  • t - list the contents of the archive
  • v - verbose
  • x - extract files
  • z - compress using gzip

Incremental backups can be set up using the following to find all files changed in the last 24 hours

  • find / -mtime -1 -type f -print
  • tar cvf /path/to/backupfile 'find /-mtime -1 -type f -print'
Advertisements
Tagged ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: