Passwordless SSH

Tired of having to retype your password each time you login to that remote computer?
Let me show you how to setup passwordless ssh.
Generate public and private keys on your client computer. Leave the passphrase empty.

user@local:~$ ssh-keygen -t rsa

Distribute your public key (~/.ssh/ to each servers .ssh/authorized_keys file.
user@local:~$ cat ~/.ssh/ | ssh user@servername 'tee -a .ssh/authorized_keys'
Security concerns: If someone gets hold of your private key AND your left the passphrase empty, the he will have access to all of the remote computers just as you.

[ad#Google Adsense-1]

How to flush DNS cache Linux, Mac OS X, Windows

[ad#Google Adsense-1]
To flush DNS cache on Microsoft Windows (Win Vista, Win 7)

Run hte command prompt with Administrator privileges

Type ipconfig /flushdns

To flush the DNS cache on Linux, restart the nscd daemon:-

Linux does not cache dns by default. Some systems might have a dns cahcing service such as nscd. Restarting the DNS caching service will flush the DNS cache.

To restart the nscd daemon, type /etc/rc.d/init.d/nscd restart in your terminal, on Ubuntu or Debian you need to use sudo service nscd instead

To flush the DNS cache in Mac OS X 10.6 Snow Leopard

type dscacheutil -flushcache in the Terminal


[ad#Google Adsense-1]

Bash script to monitor disk space and email alerts if space is low, great to use with crontab

Wrote this for FreeBSD, should run on Linux with minor modifications.
(fix the paths, and replace jot with seq)

# Bash script to monitor disk space
# It will email $ADMIN if disk space goes below
# Pétur Ingi Egilsson # 3 March 2011
#Device to monitor
#Min space in KiB
MinDisk[1]=500000 # 500 MiB
MinDisk[2]=500000 # 500 MiB
MinDisk[3]=500000 # 500 MiB
for i in `/usr/bin/jot - 1 ${#Disk[@]}`;
space=`/bin/df -k ${Disk[$i]} | /usr/bin/awk '{print $4}' | tail -n 1`
if [ $space -le ${MinDisk[$i]} ];
then /bin/echo "Warning: ${Disk[$i]} has $space KiB left" | /usr/bin/mail -s $SUBJECT $ADMIN;

9 OS X Command Line Utilities you probably didn’t know about

OS X is ment to be a clean and a simple operating system,
yet under the hood it’s very powerful.

Here I shall go over 9, rather random, commands.
You can learn more about them by typing “man command-name” in the console.
Example, “man shutdown”.

Here we go!

1. shutdown
The command shutdown will shut down the system.

It must be run as root, by using the sudo prefix (which makes the command run as root)
Reboot the computer
sudo shutdown -r now
Halt the computer (turn if off)
sudo shutdown -h now
Put the computer to sleep
sudo shutdown -s now
2. say
This tool uses the Speech Synthesis manager to convert input text to audible speech.

3. screencapture
The screencapture command can be used to capture a screenshot of the computer.
box:- petur$ screencapture screen.png
“Why on earth would you want to do that using the command line?”, you might ask. Because you can capture screenshots of remote computers, proven that you have root access to it via ssh.
It could also be useful in some situations to make a screenshot of a particular computer every x-minutes by combining ‘screencapture’ with the root crontab. Unfortunately crontab is, as I would say, an advanced topic and it will not be covered in this post.
4. arch
The arch command with no arguments, displays the machine’s architecture type.

The results can be read as follow:
i386 : 32-bit intel
x86_64 : 64-bit intel
ppc : 32-bit powerpc
ppc64 : 64-bit powerpc
5. top
The top CLI (Command Line Interface) equvalient of the Activity Monitor.

6. file
The file command is used to determine a file type.

Usage: file filename

7. iostat
iostat reports I/O statistics.
In other words, the load on your hard disk and the cpu.

Those numbers can be a little difficult to understand at first,
tps stands for Transfers per Second
KB/t stands for kilobytes per Transfer
MB/s stands for megabytes per second.

8. df
df stands for “display free”, as in display free disk space.
It’s one of those utilities you can’t be without!
-l filters out all non-local filesystems
-h makes the output more human friendly (Gi and Mi instead of plain Bytes)

9. vm_stat
Virtual memory Statistics
the hit rate is perhaps the most important information,
as a high rate indicates that you should add more RAM (memory) to your computer.

Please share your thoughts with me,
if you have any questions don’t hesitate to ask!