Copying with CPIO

Create a cpio archive:

localhost% find path/ -depth -print | cpio -oaV > archive.cpio
localhost% find path/ -depth -print | cpio -oaV -O archive.cpio

Create a cpio archive and compress it:

localhost% find path/ -depth -print | cpio -oaV | gzip -c > archive.cpio.gz

Extract a cpio archive:

localhost% cpio -imVd < archive.cpio
localhost% cpio -imVd -I archive.cpio

List the contents of a cpio archive:

localhost% cpio -it < archive.cpio
localhost% cpio -it -I archive.cpio

Use cpio copy-pass to copy a directory structure to another location:

localhost% find path/ -depth -print | cpio -pamVd /new/parent/dir

cpio over SSH

To cpio a local directory, send the output to ssh and feed it to cpio on a remote host:

localhost% find path/ -depth -print | cpio -oaV | ssh user@host ‘cpio -imVd’
Ssh to a remote host, cpio a remote directory, and get its output locally:
localhost% ssh user@host “find path/ -depth -print | cpio -oaV” | cpio -imVd

cpio and rpm

Ever wanted to extract files from an RPM package without installing it? It’s easy. RPMv4 includes a utility called “rpm2cpio”, which creates a cpio stream of files from a given RPM. You can pipe this into cpio just like a regular archive or stream.

List the included files:

localhost% rpm2cpio foo.rpm | cpio -it

Extract all files:

localhost% rpm2cpio foo.rpm | cpio -imVd

Extract only the manpage from that package:

localhost% rpm2cpio foo.rpm | cpio -imVd ./usr/share/man/man1/foo.1.gz


How to move a Virtual Machine From EC2 to VirtualBox or KVM

There have been quite a few requests on forums and blog posts on a few sites we frequent asking someone to figure out how to move a virtual machine from EC2 to VirtualBox or KVM. We’ve got quite a bit of experience working with KVM so we figured why not try our hand at importing a virtual machine template from the Amazon AMI repository so that developers or sysadmins could run them in their local environments. We’ve already written a howto on importing an AMI from Amazon, so you may want to read that first, but this howto also applies to just creating a KVM or VirtualBox image from a linux filesystem of any kind. Right now this particular method only works with Linux but there are more OS agnostic (and much slower) methods for transposing virtual machines. So without further delay, let’s get started.

Continue reading ‘How to move a Virtual Machine From EC2 to VirtualBox or KVM’

Passwordless SSH authentication with Putty

Putty from here. Download  PuttyGen from same link. Once installed, open Puttygen and create a new pair of keys by clicking the “Generate” button. You can keep all the options at their default settings. It might be a good idea to set a passphrase for your key. Then, save both public and private key to a safe location. Name your public key <your_key_name>.pub and the private key <your_key_name>.ppk.

Continue reading ‘Passwordless SSH authentication with Putty’

HOWTO SSH back door?

Many times I’ll be at a site where I need remote support from someone who is blocked on the outside by a company firewall. Few people realize that if you can get out to the world through a firewall, then it is relatively easy to open a hole so that the world can come into you.

In its crudest form, this is called “poking a hole in the firewall.” I’ll call it an SSH back door. To use it, you’ll need a machine on the Internet that you can use as an intermediary.

In our example, we’ll call our machine The machine behind the company firewall is called ginger. Finally, the machine that technical support is on will be called tech. Figure 4 explains how this is set up.


Here’s how to proceed:

1. Check that what you’re doing is allowed, but make sure you ask the right people. Most people will cringe that you’re opening the firewall, but what they don’t understand is that it is completely encrypted. Furthermore, someone would need to hack your outside machine before getting into your company. Instead, you may belong to the school of “ask-for-forgiveness-instead-of-permission.” Either way, use your judgment and don’t blame me if this doesn’t go your way.

2. SSH from ginger to with the -R flag. I’ll assume that you’re the root user on ginger and that tech will need the root user ID to help you with the system. With the -R flag, you’ll forward instructions of port 2222 on blackbox to port 22 on ginger. This is how you set up an SSH tunnel. Note that only SSH traffic can come into ginger: You’re not putting ginger out on the Internet naked.

You can do this with the following syntax:

~# ssh -R 2222:localhost:22

Once you are into blackbox, you just need to stay logged in. I usually enter a command like:

thedude@blackbox:~$ while [ 1 ]; do date; sleep 300; done

to keep the machine busy. And minimize the window.
3. Now instruct your friends at tech to SSH as thedude into blackbox without using any special SSH flags. You’ll have to give them your password:

root@tech:~# ssh .
4. Once tech is on the blackbox, they can SSH to ginger using the following command:

thedude@blackbox:~$: ssh -p 2222 root@localhost
5. Tech will then be prompted for a password. They should enter the root password of ginger.

6. Now you and support from tech can work together and solve the problem. You may even want to use screen together! (See Trick 4.)

Source: IBM DeveloperWorks

PostgreSQL DBA Commands

In this article, We review top 15 practical postgreSQL DBA command examples.
Continue reading ‘PostgreSQL DBA Commands’

Upgrading openSUSE 10.3 –> 11.0 in a running system.

Upgrading openSUSE between releases while the system is running is not a currently supported method of upgrading. The supported method is to boot from an install medium and select the upgrade option. Nevertheless, it is possible to upgrade a running system. This is more difficult than normal with openSUSE 10.3 -> openSUSE 11.0 due to the change in RPM payload format from bz2 -> lzma which makes the RPM in 10.3 unable to install RPMs from 11.0.
Continue reading ‘Upgrading openSUSE 10.3 –> 11.0 in a running system.’