OpenSUSE Linux Rants

OpenSUSE Linux Tips, tricks, how-tos, opinions, and news

My Resume  -  My LinkedIn Profile

November 1, 2009

OpenSUSE Linux: Quick Zypper Tutorial

by @ 1:21 am. Filed under bash, command-line, SUSE Tips & Tricks

OpenSUSE Linux provides a command-line method of managing repositories and packages. This tool is called zypper. The following is a basic tutorial by example of how to use zypper.

Repository Management

To list repositories:

[1342][root@dev:/home/scott]$ zypper repos
#  | Alias             | Name                  | Enabled | Refresh
1  | Enlightenment CVS | Enlightenment CVS     | Yes     | Yes    
2  | OpenSUSE_11.1_ISO | OpenSUSE 11.1 ISO     | Yes     | No     
3  | Packman           | Packman               | Yes     | Yes    
4  | Window_Managers   | Window Managers       | Yes     | Yes    
5  | XFCE4             | XFCE4                 | Yes     | Yes    
6  | aterm             | aterm                 | Yes     | Yes    
7  | home:danci1973    | home:danci1973        | Yes     | Yes    
8  | home:dauphin      | home:dauphin          | Yes     | Yes    
9  | home:jnelson-suse | home:jnelson-suse     | Yes     | Yes    
10 | mozilla           | mozilla               | Yes     | Yes    
11 | openSUSE 11.1-0   | openSUSE 11.1-0       | Yes     | Yes    
12 | repo-debug        | openSUSE-11.1-Debug   | No      | Yes    
13 | repo-non-oss      | openSUSE-11.1-Non-Oss | Yes     | Yes    
14 | repo-source       | openSUSE-11.1-Source  | No      | Yes    
15 | repo-update       | openSUSE-11.1-Update  | Yes     | Yes    

To add a repository (we’re going to use Packman as an example):

[1341][root@dev:/home/scott]$ zypper addrepo "" Packman
Adding repository 'Packman' [done]
Repository 'Packman' successfully added
Enabled: Yes
Autorefresh: No


To turn on autorefresh, because it’s disabled by default (again, with Packman):

[1341][root@dev:/home/scott]$ zypper modifyrepo -r Packman
Autorefresh has been enabled for repository 'Packman'.

To refresh a repo manually:

[1342][root@dev:/home/scott]$ zypper refresh -r Packman
Retrieving repository 'Packman' metadata [done]
Building repository 'Packman' cache [done]
Specified repositories have been refreshed.

Leave out the “-r” and leave off the name of the repo if you want to refresh all of them.

To remove a repository:

[1337][root@dev:/home/scott]$ zypper rr Packman
Removing repository 'Packman' [done]
Repository 'Packman' has been removed.

Package Management

To search for a package (id3v2, in this example):

[1224][root@dev:/home/scott]$ zypper search id3v2
Loading repository data...
Reading installed packages...

S | Name  | Summary                              | Type   
  | id3v2 | A Command Line Editor for ID3V2 Tags | package

To get information on a package (again, id3v2):

[1229][root@dev:/home/scott]$ zypper info id3v2
Loading repository data...
Reading installed packages...

Information for package id3v2:

Repository: openSUSE 11.1-0
Name: id3v2
Version: 0.1.11-77.60
Arch: x86_64
Vendor: openSUSE
Installed: No
Status: not installed
Installed Size: 79.0 K
Summary: A Command Line Editor for ID3V2 Tags
ID3 tags are found in MP3 files. They canstore information about what band recorded the song, the song name, and more.

ID3V1 tags are seriously deficient as to the kind of and length ofinformation that they can store. This is a tool for editing ID3V2tags in Linux.


To install a package:

[1333][root@dev:/home/scott]$ zypper install id3v2
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:

Overall download size: 30.0 K. After the operation, additional 79.0 K will be used.
Continue? [YES/no]: 
Retrieving package id3v2-0.1.11-77.60.x86_64 (1/1), 30.0 K (79.0 K unpacked)
Retrieving: id3v2-0.1.11-77.60.x86_64.rpm [done]          
Installing: id3v2-0.1.11-77.60 [done]

To remove a package:

[1334][root@dev:/home/scott]$ zypper remove id3v2
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following package is going to be REMOVED:

After the operation, 79.0 K will be freed.
Continue? [YES/no]: 
Removing id3v2-0.1.11-77.60 [done]

These are some common zypper commands that will help you manage your repositories and packages from the command-line.

October 21, 2009

SSH Tip for the Day

by @ 8:14 am. Filed under bash, command-line, Linux tips, ssh tips

When you are forwarding ports through a tunnel, either locally or remotely (i.e., with the -L or -R switches), you can modify the session real-time. The way that you do this is after you start the session, you press SHIFT + ` + c (The ` key also has a ~ in it, which is the actual keypress sent to the session). If it doesn’t work the first time, press ENTER a couple of times and try it again. Once you get the “ssh>” prompt, type “?” for the commands you can put in. Here’s an example session:

[0908][scott@dev:~]$ ssh -R
Last login: Thu Oct 15 11:59:43 2009 from
Have a lot of fun...
[1109][scott@mail:~]$ [PRESS SHIFT + ` + c HERE]
ssh> ?
      -L[bind_address:]port:host:hostport    Request local forward
      -R[bind_address:]port:host:hostport    Request remote forward
      -KR[bind_address:]port                 Cancel remote forward
[1110][scott@mail:~]$ [PRESS SHIFT + ` + c HERE]
Forwarding port.


OpenSSH has got to be one of the freakin’ sweetest tools *EVAR*. Anyway, enjoy!

July 28, 2009

Linux, what nice… passwords you have… and your prompts are incredible…

by @ 6:01 pm. Filed under bash, command-line, General Linux, Linux tips

When you have the level of paranoia that I do, being able to generate ultra-secure passwords is a very nice thing.

My bash prompt is also something I take great pride in. Not only that, I really like it.

Well guess what, folks… you can do both with the same file. This would be your .bashrc file. Here’s a basic look at my prompt:


It shows me the time, the account with which I am logged in, the hostname of the local machine, and the present working directory. All handy things to know.

Now, for the password generation thing, check this out:

[1855][scott@laptop:~]$ genpasswd 64

You can make rainbow tables ’til the end of time, and let John the Ripper go on the /etc/shadow file with that password in it, and you ain’t gonna be cracking that password.

If this is interesting to you, or you have other suggestions of a similar nature, please, let’s have ’em.

That all said, here’s the .bashrc file that makes this prompt and password generator possible:

# /etc/skel/.bashrc:                                          
# This file is sourced by all *interactive* bash shells on startup.  This
# file *should generate no output* or it will break the scp and rcp commands.

# colors for ls, etc.
eval `dircolors -b /etc/DIR_COLORS`
alias d="ls --color"
alias ls="ls --color=auto"
alias ll="ls -al --color"

# Change the window title of X terminals
case $TERM in
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'

##uncomment the following to activate bash-completion:
#[ -f /etc/profile.d/bash-completion ] && source /etc/profile.d/bash-completion

function proml {
local       BLUE="\[\033[0;34m\]"
local        RED="\[\033[0;31m\]"
local  LIGHT_RED="\[\033[1;31m\]"
local      WHITE="\[\033[1;37m\]"
local LIGHT_GRAY="\[\033[0;37m\]"
case $TERM in

$BLUE[$RED\$(date +%H%M)$BLUE]\
PS2='> '
PS4='+ '


alias ifconfig="/sbin/ifconfig"

genpasswd() {
        local l=$1
        [ "$l" == "" ] && l=20
        tr -dc A-Za-z0-9\-_~\!@#$%^\&*\(\)\\\`\+\[\{\]\}\|\;:\",\<.\>/?\= < /dev/urandom | head -c ${l} | xargs

Hope that's as useful for you as it has been for me.

July 21, 2009

Linux command for “What’s up on this here box?”

by @ 8:33 am. Filed under bash, command-line, General Linux, sweet tools

Linux has so many marvelous tools. The great part about this is that you can combine the tools to make new tools. As you may know, there have been previous postings about a tool called ‘sup’ which tells you some useful information about the linux box into which you are logged. Having so many terminal windows open, and screen sessions going, it’s easy to get lost in the labyrinth of connections and sessions. This tool clears all that up for you really quick.

Since the last version, the most significant change is the ability to determine which version of which Linux distribution you are using.

Here is some sample output:

<=== SYSTEM ===>
  Distro info:  Welcome to openSUSE 11.1 - Kernel \r (\l).
  Kernel:       Linux laptop #1 SMP 2009-02-25 15:40:44 +0100 i686 i686 i386 GNU/Linux
  Uptime:        9:20am  up   0:47,  1 user,  load average: 0.64, 0.54, 0.38
  Memory:       Total: 1986Mb   Used: 730Mb     Free: 1256Mb
  Swap:         Total: 4180Mb   Used: 0Mb       Free: 4180Mb
  Architecture: i686
  Processor:    0 : Intel(R) Core(TM) Duo CPU T2250 @ 1.73GHz
  Processor:    1 : Intel(R) Core(TM) Duo CPU T2250 @ 1.73GHz
  Date:         Tue Jul 21 09:20:09 MDT 2009

<=== USER ===>
  User:         scott (uid:1000)
  Groups:       users www
  Working dir:  /home/scott
  Home dir:     /home/scott

<=== NETWORK ===>
  Hostname:     laptop
  IP (lo):
  IP (lo):
  IP (eth0):
  Name Server:


Download this “Linux ‘sup’?” script here.

July 16, 2009

SSH Attack Foghorn

by @ 6:20 am. Filed under bash, General Linux, Linux tips, ssh tips, sweet tools, Work-Related

I don’t like it when people try and hack my web servers. To make myself aware of people trying to access my ssh daemon, I wrote me a little script. Yup, I’m certainly aware of DenyHosts. Notwithstanding, in the hopes that this script may find use elsewhere, I post it here. Behold, enjoy, and chuckle a bit at how much better you could write it. Then, let me know how you’d improve it:

PATTERN="^"`date --date="1 minute ago" "+%b %e %H:%M:"`""
tail -n 1000 /var/log/messages | grep ""$PATTERN"" | grep sshd | grep -i "invalid user" | grep " from " > "$LOGFILE"
if [ $(stat -c%s "$LOGFILE") -gt 0 ] ; then
	echo "See the attached log for details" | mailx -a "$LOGFILE" -s "Possible hack attempt" YOUREMAIL@YOURDOMAIN.COM

Copy it to your /root folder. Name it something cool like ‘ssh_foghorn’, and chmod +x it to make it executable. Put it in your /etc/crontab file to run once every minute. Make sure you set the system log to whatever your distro uses. And change the email address to your own. Doesn’t cure cancer, but for 8 lines of code, it does what it needs to.

Again, I’m sure there are better ways to do this, so let’s hear ’em!

April 3, 2009

Linux Commands to Create NTFS Filesystem on USB Stick

by @ 9:26 am. Filed under bash, command-line, How-To, Linux tips

First, the stick should be in, but not mounted. If it is mounted, find the partition represented by your usb stick, as such:

[0959][scott@laptop:~]$ mount
/dev/sda2 on / type ext3 (rw,acl,user_xattr)
/proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
debugfs on /sys/kernel/debug type debugfs (rw)
udev on /dev type tmpfs (rw)
devpts on /dev/pts type devpts (rw,mode=0620,gid=5)
/dev/sda1 on /windows/C type fuseblk (rw,allow_other,blksize=4096)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /home/scott/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=scott)
/dev/sdc1 on /media/disk-1 type vfat (rw,nosuid,nodev,shortname=winnt,uid=1000)
/dev/sdb1 on /media/disk-2 type fuseblk (rw,nosuid,nodev,allow_other,default_permissions,blksize=1024)

It will likely be a /dev/sdxx type device. In this case, the one I’m looking for is sdb1.

We need to unmount it as root (‘su’):

laptop:/home/scott # umount /dev/sdb1
laptop:/home/scott #

Now, fdisk the usb stick, and not the partition. In other words, leave off the trailing digit:

laptop:/home/scott # fdisk /dev/sdb

Command (m for help):

Press ‘p’ to view the partitions on the drive. Delete all partitions. Create a new one with ‘n’. It will be a primary partition, and it will be partition 1. Now, we need to set the filesystem type. Press ‘t’, and then if you’d like to see all the filesystem types, press ‘L’, but I’ll just tell you that NTFS is 7. Press ‘7’, and then ‘w’ to write the partition table, and exit:

Command (m for help): p

Disk /dev/sdb: 1027 MB, 1027604480 bytes
64 heads, 32 sectors/track, 980 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk identifier: 0x610fbfb2

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         980     1003504    c  W95 FAT32 (LBA)

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-980, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-980, default 980):
Using default value 980

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 7
Changed system type of partition 1 to 7 (HPFS/NTFS)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
laptop:/home/scott #

Now, we need to actually format the new partition. Include the partition number at the end. It should be 1. You will do this as root (‘su’), like so:

laptop:/home/scott # mkntfs /dev/sdb1
Cluster size has been automatically set to 1024 bytes.
Initializing device with zeroes: 100% - Done.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
laptop:/home/scott #

K, well, there you are. Mount it up any way you see fit, and you are all set.

January 21, 2009

Linux Tells Us What’s Up (new version of ‘sup’ tool!)

by @ 9:44 am. Filed under bash, sweet tools

I have updated the ‘sup’ bash script so that you can see some useful stats about your Linux box at a glance. Here is some output:

  User:         scott (uid:1000)
  Groups:       users dialout video
  Working dir:  /home/scott
  Home dir:     /home/scott
  Hostname:     suse-linux
  IP (lo):
  IP (lo):
  IP (eth0):
  Name Server:
  Date:         Wed Jan 21 09:38:57 MST 2009
  Uptime:        9:38am  up 15 days 23:36,  6 users,  load average: 0.22, 0.22, 0.24
  Kernel:       Linux suse-linux #1 SMP 2008-10-21 16:30:26 +0200 i686 i686 i386 GNU/Linux
  Memory:       Total: 2016Mb   Used: 972Mb     Free: 1044Mb
  Swap:         Total: 4102Mb   Used: 150Mb     Free: 3952Mb
  Architecture: i686
  Processor:    0 : Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
  Processor:    1 : Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz

I’ve added the processor info and gateway and nameserver info. I’ve commented out some other stuff that will give you your sound card info, video card info, and basically everything you can get with “lspci -v”. That would be why it’s commented out. Anyway, take a look at the new version:

Linux ‘sup’ bash script

May 31, 2008

What’s Up must come Down – and boy did it ever

by @ 6:57 am. Filed under bash

As Linux tools sometimes do, this little script was born out of frustration from the repetitive. And the meniality of the task is directly proportional to one’s desire to replace it with anything that will automate the process. If I have to do something twice on my Linux box, it gets automated.

So a few days ago I put together a bash script which I named “What’s Up?” The abbreviation for this is ‘sup’ which is the command used to invoke the script. I use it to tell me which server I’m on, who I’m logged in as, the memory status of the box, and some other crazy junk.

Originally, this fool was 110 lines of code to display 13 lines of output. Fortunately, an altruistic and knowledgeable Lonnie Olson brought to my attention the fact that there was room for some nice optimizations. Of such coolness were these optimizations that they brought the line count from 110 to a mere 21, not including comments and empty lines.

If you’re just tuning in, the script looks like this:



KERNEL=`uname -a`


printf "  user:\t\t"$USER" (uid:"$UID")\n"
printf "  groups:\t"$MYGROUPS"\n"
printf "  working dir:\t"$CPWD"\n"
printf "  home dir:\t"$HOME"\n"
printf "  hostname:\t"$HOSTNAME"\n"
ip -o addr | awk '/inet /{print "  IP (" $2 "):\t" $4}'
printf "  date:\t\t"$DATE"\n"
printf "  uptime:\t"$D_UP"\n"
printf "  kernel:\t"$KERNEL"\n"
printf "  cpu:\t\t"$CPU"\n"
free -mot | awk '
/Mem/{print "  Memory:\tTotal: " $2 "Mb\tUsed: " $3 "Mb\tFree: " $4 "Mb"}
/Swap/{print "  Swap:\t\tTotal: " $2 "Mb\tUsed: " $3 "Mb\tFree: " $4 "Mb"}'

NOTE: If you copy and paste the above code and it does not work, just download it from the link provided above.

And its output looks like this:

[0137][scott@tomahawk:~]$ sup
  user:         scott (uid:1000)
  groups:       users dialout video
  working dir:  /home/scott
  home dir:     /home/scott
  hostname:     tomahawk
  IP (lo):
  IP (eth0):
  date:         Sat May 31 01:57:54 MDT 2008
  uptime:        1:57am  up 2 days 21:53,  5 users,  load average: 0.27, 0.23, 0.18
  kernel:       Linux tomahawk 2.6.24-default #1 SMP Sat Jan 26 21:54:20 MST 2008 x86_64 x86_64 x86_64 GNU/Linux
  cpu:          x86_64
  Memory:       Total: 940Mb    Used: 925Mb     Free: 14Mb
  Swap:         Total: 1913Mb   Used: 349Mb     Free: 1564Mb

Logging into and out of many Linux servers per day with many different users can cause you to develop aggravated multiple personality disorders unless of course you use a cool script like this to cue the gray matter. I’m thinking about writing another one called ‘whoami’. Oh wait, someone already did that.

May 28, 2008

“What’s up?” bash script redone, revised, and mo’ bettah

by @ 12:25 pm. Filed under bash, freebies

A couple of days ago, I put together a .bashrc alias. Well, it won’t work right. The commands in “ marks only execute when the shell opens, and then the variables they’re assigned to stay the same, even when you invoke the alias. Thus, the current working directory and the date and stuff that should change each time you invoke the alias, don’t.

To fix this, I changed it from an alias into a small bash script. To use it, just put it into your ~/bin folder and invoke it like you would any other command.

The contents are thus:



function memdisp {

IFS=$' '

MEM=`free -mot | head -n 2 | tail -n 1`

printf "  Memory:"

for ITEM in $MEM
        if [ $COUNT -eq 2 ] ; then
                printf "\tTotal: $ITEM Mb"

        if [ $COUNT -eq 3 ] ; then
                printf "\tUsed: $ITEM Mb"


        if [ $COUNT -eq 4 ] ; then
                printf "\tFree: $ITEM Mb\n"


MEM=`free -mot | tail -n 2 | head -n 1`


printf "  Swap:\t"

for ITEM in $MEM
        if [ $COUNT -eq 2 ] ; then
                printf "\tTotal: $ITEM Mb"

        if [ $COUNT -eq 3 ] ; then
                printf "\tUsed: $ITEM Mb"


        if [ $COUNT -eq 4 ] ; then
                printf "\tFree: $ITEM Mb\n"



function ipaddr {

IFS=$' '
IPINF=`/sbin/ifconfig eth0 | head -n 2 | tail -n 1`

printf "  IP (eth0):"
for ITEM in $IPINF
        if [ $COUNT -eq 2 ] ; then
#                 printf "$ITEM\n"
                for DATA in $ITEM
                	if [ $CT -eq 2 ] ; then
                		printf "\t$DATA\n"


KERNEL=`uname -a`

printf "  user:\t\t"$USER" (uid:"$UID")\n"
printf "  groups:\t"$MYGROUPS"\n"
printf "  working dir:\t"$CPWD"\n"
printf "  home dir:\t"$HOME"\n"
printf "  hostname:\t"$HOSTNAME"\n"
printf "  date:\t\t"$DATE"\n"
printf "  uptime:\t"$D_UP"\n"
printf "  kernel:\t"$KERNEL"\n"
printf "  cpu:\t\t"$CPU"\n"


If you copy and paste it, save it as ~/sup, and don’t forget to make it executable with chmod +x ~/sup.

Example output:

[1211][scott@tomahawk:~]$ sup
  user:         scott (uid:1000)
  groups:       uid=1000(scott) gid=100(users) groups=16(dialout),33(video),100(users)
  working dir:  /home/scott
  home dir:     /home/scott
  hostname:     tomahawk
  IP (eth0):
  date:         Wed May 28 12:11:58 MDT 2008
  uptime:       12:11pm  up   8:07,  7 users,  load average: 0.46, 0.43, 0.30
  kernel:       Linux tomahawk 2.6.24-default #1 SMP Sat Jan 26 21:54:20 MST 2008 x86_64 x86_64 x86_64 GNU/Linux
  cpu:          x86_64
  Memory:       Total: 940 Mb   Used: 756 Mb    Free: 183 Mb
  Swap:         Total: 1913 Mb  Used: 0 Mb      Free: 1913 Mb

Here’s a link to the script: sup.tar.bz2

Download the script.

Run: tar -xvf sup.tar.bz2

Run: mv sup ~/bin

Run: sup


May 23, 2008

Quick “what’s up?” alias for your .bashrc file

by @ 1:40 pm. Filed under bash, General Linux, SUSE Tips & Tricks

NOTE: Don’t use this, it has been updated. Go here for latest.

I was fooling around with an alias that would help someone know at a glance what machine they are on, who they are logged in as, their current path, the date, uptime, and some memory stats. This is something that I have found helpful when I have several remote servers open and logged into each one with several different accounts. It’s easy to know at a glance where I am doing what.

To implement this alias, pull open your ~/.bashrc file, and paste all of this at the end of it:

function memdisp {

MEM=`free -mot | head -n 2 | tail -n 1`
for ITEM in $MEM
        if [ $COUNT -eq 2 ] ; then
                printf "  Total RAM:\t$ITEM Mb\n"

        if [ $COUNT -eq 3 ] ; then
                printf "  Used RAM:\t$ITEM Mb\n"


        if [ $COUNT -eq 4 ] ; then
                printf "  Free RAM:\t$ITEM Mb\n"


MEM=`free -mot | tail -n 2 | head -n 1`
for ITEM in $MEM
        if [ $COUNT -eq 2 ] ; then
                printf "  Total SWAP:\t$ITEM Mb\n"


        if [ $COUNT -eq 3 ] ; then
                printf "  Used SWAP:\t$ITEM Mb\n"


        if [ $COUNT -eq 4 ] ; then
                printf "  Free SWAP:\t$ITEM Mb\n"





alias sup="
printf '  my user:\t`whoami`\n'
printf '  my groups:\t`id`\n'
printf '  hostname:\t`hostname`\n'
printf '  domain:\t`dnsdomainname`\n'
printf '  date:\t\t`date`\n'
printf '  uptime:\t$D_UP\n'
printf '  kernel:\t`uname -a`\n'

Then save the file, and run “source ~/.bashrc”. To use the alias, type ‘sup’ (short for “what’s up?”) and hit ENTER. You should see something like this:

[1457][scott@suse-linux:~]$ sup
  my user:      scott
  my groups:    uid=1000(scott) gid=100(users) groups=16(dialout),33(video),100(users)
  hostname:     suse-linux
  domain:       truenorth.local
  date:         Fri May 23 14:57:23 MDT 2008
  uptime:       2:57pm  up 5 days 18:35,  15 users,  load average: 0.17, 0.12, 0.13
  kernel:       Linux suse-linux 2.6.24-default #1 SMP Sat Jan 26 00:29:01 MST 2008 i686 i686 i386 GNU/Linux
  Total RAM:    1264 Mb
  Used RAM:     1234 Mb
  Free RAM:     30 Mb
  Total SWAP:   2055 Mb
  Used SWAP:    213 Mb
  Free SWAP:    1841 Mb

This is great for when you come back to work from a long weekend, have 300 terminal windows open, logged into 32 servers with 43 different accounts.

If you wanted, you could also put this into the /etc/skel/.bashrc file so that all new users on your machine will automatically have this alias. Change to suit your taste.

If you do this, and an FBI satellite crashes into your new Porsche, it’s not my fault.

I am under no delusions of grandeur here. If you know of a better way to output the info, or more info that you’d like to output, or you modify/change it to make it better, please let us know. Suggestions, tips, tricks, comments, and even mild insults are welcome.

March 18, 2008

ssh Without a Password

by @ 9:09 am. Filed under bash, command-line, Linux tips, ssh tips

If you use Linux for day-to-day computing, you likely use the secure shell, or ssh. If you are like me, you may grow weary of constantly having to type in passwords to access remote machines. Or maybe you have the perfect backup system, except that it uses ssh to transfer files, and requires you to type in a password (such as rsync or rdiff-backup). There is a way to access those machines without using a password. This technique should be used with care. I’d use it only on machines that I have access to, for example. You don’t want to set up passwordless access from a public machine to your production server, in other words. Use with caution.

The principle is that you generate a public and private key on the local machine. This will be whatever machine you are connecting from. You then transfer the public key to the remote machine. Then, when you ssh into the remote machine, it uses the keys to authenticate. You don’t type in a password, it just takes you straight to the shell prompt. How do we set this up?

Log into the machine you are going to connect from. Let’s say that your account is called ‘user’ and you are going to connect from a machine called ‘desktop’. Log in as ‘user’ on the ‘desktop’ machine and pull up a shell. Run this command. The stuff in red is what you do,not what you type:

[0218][user@desktop:~]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa): [JUST PRESS ENTER HERE]
Enter passphrase (empty for no passphrase): [JUST PRESS ENTER HERE]
Enter same passphrase again: [JUST PRESS ENTER HERE]
Your identification has been saved in /home/user/.ssh/id_dsa.
Your public key has been saved in /home/user/.ssh/
The key fingerprint is:
a5:25:c0:aa:fe:f3:9f:46:7a:23:e3:6e:10:ec:6f:d3 user@desktop

Your keys are generated. On that machine, view /home/user/.ssh/ You will see something like this:

ssh-dss AAAAA3NzAC1kc3MAAACAANfnr9xkAks2u8Xd5I9nozzsXLKCYA8o9h3cMwL5QMcZGxz84Dyl3IyRwozv3I2xGwJAYyAHvJAS7AQmtFXtfmQts3dt2ZnlAmKj0TkC8pwDgvXJYzARJpCP2Zx7iwD/OCO3sTgT0wGwYtQrAcTeW5Tt6sSmQjEJ2rJj+Q5XA1xvAAAAFQDWcQ+OJRnk+jCYqESWqxHcyw74DwAAAIA9qAQyZrOJkjpzMSWAcliHvvuyCN8RInlgq+IwWynukOX7zYXcE2dJPopgpG3Aiiq/fxAQX5dUzXfSrL3KYftQOd/RNkAzMHAAzAJeQAA0wEt4uAjhGRwCOSg6wKMYJPYfVghnwIKARuSTUS8NjRXVKteHg7frOOHZwRGIm36pxgAAAIA8/CKLLn5QRctsvvvmvpOn2Xhek02z8K0YukYcXJOQ1FMTYWoHujA39sEAFsdx6Nq1t58lI2dsj6fpf7LOOvoYWtKQnTNRUptlOx27LTO9Q6DhKPV/93nLI/xFOFo/8twZ1TmpAgpAI3SQ9YCnX2A8H686OUwUPmY0kA+H8GKnug== user@desktop

What you need to do now, is determine the remote machine you are going to log into. Then, decide what user you are going to log in as on that machine. We are going to log in as a user called ‘admin’ on a server called ‘server’. First, we will ssh into ‘server’ as ‘admin’. Then, edit the file located at ~/.ssh/authorized_keys2. If it is not there, create it. All you need to do is paste the contents of the file from the ‘user’ account on the ‘desktop’ machine into the ~/.ssh/authorized_keys file for ‘admin’ on ‘server’.

For example:

I go to my desktop, log in as ‘user’. I run ‘ssh-keygen -t dsa’. It generates a ~/.ssh/ file in my home directory.

I want to connect as ‘admin’ on a box called ‘server’. I ssh in normally as ‘admin’ into the ‘server’ machine. I edit the ~/.ssh/authorized_keys2 using my favorite text editor. I add the contents of the ~/.ssh/ file from my desktop machine into the authorized_keys2 file on ‘server’. I then save and quit. I then close all connections to ‘server’. Then, I type ‘ssh admin@server’, and hit ENTER. It drops me straight to a shell prompt.

This is a nice way to access a machine without having to type in the password every time. Only do this from machines that only you or authorized personnel have access to. Otherwise, you could have a li’l security problem.

January 25, 2008

Linux commands for “What is taking up all my space?”

by @ 6:49 am. Filed under bash, command-line, General Linux, How-To, Linux tips

Terminal Icon

When you’re in the trenches, pounding out solutions, it’s nice to have any added advantage that you can. Finding the source of what is taking up all the space on a given Linux partition may just find itself on your priority list some day. And when you need to know right now where it is, it’s great to have the following solutions.

Should you need to find the source of what is taking up the space on one of your Linux boxen, you can use this command to get you through:

stage:/ # du -s * | sort -g
0       proc
0       sys
4       media
4       mnt
16      lost+found
68      tmp
100     srv
112     dev
2564    home
7568    bin
9280    sbin
9916    boot
28528   etc
70844   lib
209624  var
221708  root
429396  opt
1848788 VM
2686844 usr
stage:/ # 

So now obviously, my /usr path is taking up the most space. Let’s head into /usr and run the command again:

stage:/ # cd usr
stage:/usr # du -s * | sort -g
0       tmp
12      X11R6
16      i586-suse-linux
76      local
3404    games
12124   include
18100   sbin
100424  bin
331616  src
1103240 share
1117832 lib
stage:/usr # 

We then see that /var/lib and /var/share are taking up the most space.

Once you find the culprits, you can archive them, back them up, truncate them, or just plain rm them (please use ‘rm’ with care).

Also, if you are looking for all files on your drive larger than a certain size, the following script may be useful to you. Don’t forget to ‘chmod +x’ it to make it executable:


# In kilobytes on older machines


# Find the files and put them in a list
FILELIST=`find . -size +"$MINSIZE"k -print`

for FILE in $FILELIST ; do

        FILESIZE=`stat \-\-format=%s "$FILE"`
        FILEM=$(echo "scale=2;$FILESIZE/1048576" | bc -l)
        printf ""$FILE"\\n"
        printf "\\tsize is "$FILEM" Megabytes\\t"
        printf "\\ttype is `file -b "$FILE"`\\n\\n"


You may ask, “What is this IFS thing?” Well, it is explained quite well on But for those of us who don’t want to go read that, I’ll just copy and paste the important part for ya’ll:

internal field separator

This variable determines how Bash recognizes fields, or word boundaries, when it interprets character strings.

In other words, bash by default uses spaces to separate things into lists. You are telling it to split the list of files up by the \n or carriage return character rather than by spaces.

Anyway, use the command demonstrated above, and the bash script demonstrated below, to find the files that are taking up all your space.

June 21, 2007

Automate Installation of Web Server in openSUSE 10.2 (installs Apache, MySQL, and PHP) – bash script

by @ 11:05 am. Filed under bash, freebies, SUSE Tips & Tricks

We have a special treat for anyone who manages or installs multiple machines running Linux, Apache, Mysql, and PHP. This would also be known as the LAMP stack. I got sick of having to install all that by hand every time I was putting another LAMP server together. What I have done is put together a small bash script that will automate the process of installing Apache, MySQL, and PHP. It also adds them to the init scripts, and actually starts up the MySQL and Apache services. All you have to do is set up your MySQL root password, and you are set to go. This script is available here for anyone who may find it useful. It should be easily modifiable to install perl or python for users of those tools.

Download the script here. Extract with command: “tar -jxvf”

Generally, when installing a new machine, I actually use this script I put together to automate the insertion of YAST Installation Sources as well. Run the Installation Sources script first, and then the LAMP stack script, and you’ll be 90% of the way to having yourself a web server.

April 2, 2007

synergy in openSUSE 10.2 made even easier than before

by @ 7:03 am. Filed under bash, SUSE Tips & Tricks

Since last week, I have continued using synergy between my desktop and my laptop. I did get tired of running it manually from the command line every time I wanted to load it up. Because of this, I wrote some bash scripts. To start the server and client wasn't rocket science.

To start the synergy server, this is my bash script:

synergys -f --config synergy.conf > /dev/null 2>&1 &

To start the synergy client, this is my bash script:

synergyc -f --name laptop tomahawk > /dev/null 2>&1 &

Shutting down the synergy server wasn’t hard, either.

To stop the synergy server:

killall synergys

To stop the synergy client:

killall synergyc

But how does that stop me from having to run everything from the command line? It doesn't. This is why I made launcher buttons in my KDE Panels. I made one button for each of the scripts above. I put one button in on my desktop that links to the synergy server start script. I put another on the same machine pointing to the synergy server stop script. I also put launcher buttons in my KDE Panel on my laptop. These pointed, of course, to the synergy client start and stop scripts on that machine.

Now it is very easy. I click the Panel button on my desktop machine to start the synergy server. I then click the Panel button on my laptop to start the synergy client. They connect, and poof, I’m done. When I want to close up shop, I just click the button in the Panel on my desktop that runs the synergy server stop script. Then, I click the button on my laptop that points to the synergy client stop script.

Even more convenient than before.

January 9, 2007

Backing It Up Linux-style

by @ 9:06 am. Filed under bash, freebies

Here we go with another semester of school. Could someone please take a belt sander to my eyeballs?

At work, we have a script that I wrote for backing up our files, code, and data. It is actually one script for the filesystem backups, and one script for the database backups.

I am providing the filesystem backup script here in hopes that it may be of help to someone.

That said, let me tell you a little about it.

This script is meant to perform both full backups and incremental daily backups of a directory and all contents. It creates a bzipped tarball of it and then copies it over to a CIFS share. In our case, our tape backup is on the machine with the CIFS share.

How hard is it to run tar and then cp? It isn’t. What is harder is completely automating the entire process and taking close care to watch the success of every step. It should never fail, but if something does, retry a certain number of times. Log all steps and their outcome to a log file. When the script finishes, email the last 50 lines of the log to the system administrator.

Every step is verified. Meaning that any time a file is copied, the source and destination files are checked to make sure they are identical. Any time any command is executed, the return code is checked to make sure what we think should have happened is what actually happened.

It is pretty robust, and hasn’t even blinked since I gave my final approval to push it live. It could very easily be adapted to back stuff up to FTP or an NFS share or whatever else you need to back it up to.

If you would like to take a look, you can grab it here. Run it without any parameters to see how to use it. You will need to go into the script and put in the CIFS share, username, password, and local mount point. I was going to put everything on the commandline, but I was short on time, so I only put stuff on the command line that would change from machine to machine on our network. The CIFS share is always the same, so I just put that stuff directly into the script.

If you find it helpful, post a comment here and let me know.

OpenSUSE Linux Rants
Official OpenSUSE Linux Site

internal links:


SUSE Resources

search blog:


February 2018
« Mar    

70 queries. 1.574 seconds