Linux Tips

From LinodeWiki

Jump to: navigation, search
  • To provide information on the kernel's view of memory.
cat /proc/meminfo 
  • To provide information on the kernel's view of the cpu.
cat /proc/cpuinfo 
  • If you don't have the uname application and you want to find the kernel version
cat /proc/sys/kernel/osrelease
  • If you add the "noatime" option to the /etc/fstab file for mounting options, Linux will not keep track of the access time every time a file is read. This can be of noticeable benefit on older, slower machines
  • To make your SSH more secure do the following

1. In /etc/ssh/sshd-config change the following to say:

Protocol 2
PermitRootLogin no 

2. Add your username to the wheel group:

usermod -G wheel username

3. In /etc/pam.d/su uncomment the following line to require a user to be in the "wheel" group:

auth required /lib/security/pam_wheel.so use_uid
  • To output a list of all your iptables rules AND a packet counter and byte counter as well!
/sbin/iptables –xnvL
  • Having Problems with the kernel or hardware? Use this command:
tail /var/log/messages
  • Don't forget you can watch for data as it's being appended to any file.
tail -f  file
  • Let's say you've got some daemon process that is just running away. It's spawning more and more processes Here's a cute way to kill all of those processes
ps auxww | grep "daemonname" | awk '{print $2}' | xargs kill -9
  • To su to the root user and load the root profile and the root path use the following command
su -
  • Install an RPM:
rpm -i rpmname.rpm
  • Remove an RPM:
rpm -e rpmname.rpm  
  • Upgrade an RPM:
rpm -U rpmname.rpm 
  • Querying an all rpm installed in the system
rpm -qa
  • List all files in an rpm
rpm -ql rpmname  
  • List all the files in an rpm file that has not been installed on your system
rpm -qp rpmname.rpm –ql
  • If someone happens to create a filename named '*' do NOT do the following: rm * Instead do: rm "*"
  • Use distcc to compile across several hosts. Great for compiling xfree86, kde, gnome. Saves loads of time and is very efficient if done on a lan.
  • Secure Copy through SSH:

This is handy if you need to copy a file through an encrypted tunnel on one system to another when the file is not under the web or FTP directory.

scp [filename] [remote host address]:/path/remote/computer
  • To report all open TCP/IP and UDP ports and shows what application opened each port use:
netstat –pan
  • To get a nice bash shell prompt add the following line to your ~/.bash_profile
export PS1=”[\u@\h \W]\$”
  • {HOME}/.ssh/ssh_config can make your life a bit easier. You can use that file to specify different behaviors by hostname, etc. Read the man pages for ssh_config.
  • To print the PID of a process use:
/sbin/pidof [process name] 
  • To show a file in reverse order use:
tac
  • If you want to run a command and make it immune to hang-ups start the command using 'nohup'
nohup scriptname.sh &

You can look the progress of your nohup session in less by pressing shift-f:

less nohup.out
  • If you ever want to change the default login messages take a look at:
/etc/issue
/etc/issue.net
/etc/motd
  • Sometimes before making changes to a partition table or MBR, it is probably a good idea to perform a backup.
dd if=/dev/hda of=/tmp/hda.boot.mbr bs=512 count=1
  • To locate large files on your system as root use:
du -ax / | sort -nr | less
  • To identify a process or socket that is using a file use as root the following command
fuser FILE
  • To securely backup across the net using SSH use:
tar cvjpf - /DIRNAME | ssh BKUP_HOST "cat > destfile.tbz"
  • To SSH port forward to get to your mail server? Forward local 25 thru your border firewall.
ssh -L 11101:secondhost:22 bob@firsthost
ssh -p 11101 -L 11102:thirdhost:22 bob@localhost
ssh -p 11102 bob@localhost
Personal tools