Tag Archives: linux

ProxMox VE Virtualization

If you haven’t seen it by now, ProxMox VE is a very nice easy to use virtualization solution based on Debian Linux and KVM/OpenVZ. KVM is used to provide full virtualization where you can take an ISO and make a complete virtual server. OpenVZ is a virtual container solution which essentially provides an OS environment without the overhead of full virtualization. ProxMox has an AJAX based web GUI and is GPL. Other solutions I’ve looked at are segways into their enterprise product, so their community (GPL) version is limited.

Rather than reinvent the wheel here and write up my own tutorial, check out this one at Griffon’s IT Library!

Working with Screen

Source: http://www.ghacks.net/2010/05/14/some-cool-linux-tipstricks/
Collaborate with the screen command

Let’s say you and your co-worker are both working on debugging an application and your partner has run into a snag. Instead of having to march back and forth between offices, or leaving the comfort of your own chair (you lazy thing), you can log onto your co-workers machine and collaborate! Here’s how it works. Both machines will be Linux machines and both will have ssh accessibility. If you need to help your co-worker out follow these steps:

1. Secure shell into your friends machine…the only catch is, you have to log on with his username/password.
2. Issue the command screen -s NAME Where NAME is any name you want.

Now your co-worker has to open up a terminal window and issue the command screen -x NAME Where NAME is the same name you used in your command. Now whenever either of you type in your screen both of you will see what is going on at the same time.

To detach yourself from this session you have to hit a and then d. That means hold down , hit a, and then hit d. You will be released from the session.

Working with .deb and .rpm packages

To list all packages installed on the system, from a terminal prompt enter:

dpkg -l
rpm -qa

Depending on the amount of packages on your system, this can generate a large amount of output. Pipe the output through grep to see if a specific package is installed:

dpkg -l | grep apache2
rpm -q httpd  or  rpm -qa | grep httpd

To list the files installed by a package, in this case the ufw package, enter:

dpkg -L ufw
rpm -qpl ufw

If you are not sure which package installed a file:

dpkg -S /etc/host.conf
base-files: /etc/host.conf

rpm -qf /etc/host.conf
setup-2.5.58-7.el5

To show information about an installed package:

dpkg -p {package}
rpm -qi {package}

To show information about a package file:

dpkg -l {package.rpm}
rpm -qpi {package.rpm}
yum info {package}

To show information about an installable package:

apt-cache show {package}
yum list {package}

To see what license an installed package uses:

rpm -qi {package} | grep License

To see what license a downloaded (not installed) package uses:

rpm -qip {package} | grep License

To get a package list so you can install the same packages on a different machine:

For .deb systems:

On first machine:
sudo dpkg -l | egrep -v ‘(rc|Desired|Status,Err|\+\+\+)’ | cut -f3 -d” ” > ~/packagelist

Then transfer ~/packagelist to your second machine to ~/ and you’ll need to setup the same repositories on the second machine as the first.

On second machine:
sudo apt-get install $(cat ~/packagelist)

To get a package list so you can install the same packages on a different machine:

For .deb systems:

On first machine:
sudo dpkg -l | egrep -v ‘(rc|Desired|Status,Err|\+\+\+)’ | cut -f3 -d” ” > ~/packagelist

Then transfer ~/packagelist to your second machine to ~/ and you’ll need to setup the same repositories on the second machine as the first.

On second machine:
sudo apt-get install $(cat ~/packagelist)

Reverting or downgrade PHP 5.3 to 5.2 in Ubuntu Lucid Lynx 10.04

Original article from:
http://www.nickveenhof.be/blog/reverting-or-downgrading-php-53-52-ubuntu-lucid-lynx-1004

I’m adding it here because of a package addition and to save it for my use.

So, you upgraded to Ubuntu 10.04 but suddenly your old applications like Drupal do not work on PHP 5.3 anymore? What the hell?

Without asking why it doesn’t work because we would only loose time we want to go back to the version of PHP 5.2 where it does work!

Let us list all existing PHP packages to know what version we are running:
dpkg -l | grep php

So, now we are going to duplicate the existing sources.list and replace the lucid with karmic repos and saving it in sources.list.d
sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list

Create a file to be a little bit ahead of our apt-get system.
sudo nano /etc/apt/preferences.d/php
And insert the following text
Package: php5
Pin: release a=karmic
Pin-Priority: 991

Let’s update the system. (You might want to do it twice to be sure)
sudo apt-get update

Installing php5 Karmic Packages. Attention! Only replace packages that were installed when doing the first command (remember the grep we did in the first step?)
sudo apt-get install php5=5.2.10.dfsg.1-2ubuntu6 php5-dev=5.2.10.dfsg.1-2ubuntu6 php-pear=5.2.10.dfsg.1-2ubuntu6 php5-cgi=5.2.10.dfsg.1-2ubuntu6 php5-cli=5.2.10.dfsg.1-2ubuntu6 php5-common=5.2.10.dfsg.1-2ubuntu6 php5-curl=5.2.10.dfsg.1-2ubuntu6 php5-gd=5.2.10.dfsg.1-2ubuntu6 php5-mcrypt=5.2.10.dfsg.1-2ubuntu6 php5-mysql=5.2.10.dfsg.1-2ubuntu6 php5-pgsql=5.2.10.dfsg.1-2ubuntu6 libapache2-mod-php5=5.2.10.dfsg.1-2ubuntu6

To not have Ubuntu upgrade php, do the following:

echo "php5-common hold" | dpkg --set-selections
echo "php5-cgi hold" | dpkg --set-selections

Using PuTTY Without Password Prompting

PuTTY is a great SSH terminal progam for Windows. Using this tutorial you’ll be able to auto login to a remote server without being prompted for a username or password. Do NOT do this in a public machine.

1. Download PuTTY from http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.60-installer.exe

2. Install and then run PuTTYgen from the programs menu.

3. Select SSH2-DSA from the bottom and hit the Generate button. Move the mouse a bit and hit ctrl-c to copy the key.

4. Click on Save Private Key. Click Yes to save it without a passphrase. I would put it in your “My Documents” directory, but you can place it wherever. Make sure you save it with a .ppk extension.

5. Open the Pageant  program for the PuTTY menu. It will put in icon in the system tray. Right click on it and click on Add Keys. Now navigate to where you saved the key file, select it, and hit Open.

6. Lauch PuTTY and type in the hostname to connect to. Type the name again in the Saved Sessions. Then click on the Data option under Connections and put your username in the Auto-login field. Click on Session at the top then click Save to save the session.

7. Click Open and PuTTY will connect to the server and display “Using Username “<your user>”. Put in your password.

8. If you’ve never used SSH from your target server, you will now need to “ssh localhost” so your .ssh directory will be created and with the right permissions. If you had to ssh localhost, now type exit to get back to your original shell and cd into the .ssh dir.

9. Use your favorite text editor to create “authorized_keys2” and paste your key into it (right or middle mouse button).

10. Permissions on authorized_keys2 will probably be -rw-rw-r– so you will need to type “chmod g-w authorized_keys2” to remove group write access, otherwise authorized_keys2 will not be used by ssh.

11. Close your shell session and open PuTTY again. If you did this right then you will now be able to double click on your host and connect without being prompted for a username or password. Another option to open the host is to right click on the Pageant tray icon and click on Saved Sessions to open up a comonly access host.

12. You will now need to get the Pageant program launched upon Windows Startup so you don’t have to open it every time. This can be done by (at least in Vista) by going to the Start Orb, All Progams, PuTTY, right click on Pageant and select copy. Now scroll down and right click on Startup and click Open. Now right click in the empty white space and select Paste Shortcut.

13. You will probably want to start Pageant at windows startup and/or start pageant with your saved key loaded. To do so, right click on the Pageant shortcut, click on properties, then change the target to something like this – “C:\Program Files\PuTTY\pageant.exe” “C:\Documents and Settings\ptrost\My Documents\key.ppk”

14. The quickest way to retrieve the key if you want to add it to another server and it’s not in your copy/paste buffer) is to open up PuTTYgen again and click Load, then select your previously saved key file. Then you can right click in the public key box to select all then again to copy.

Using Bash through the WWW

This tip came from a friend of mine:

I thought you might find something I did useful.  It grants root shell access via a browser using xinetd.  Just DO NOT put it on a public box without securing the www.bash script first (firewall port 50000 through iptables, or acls in xinetd). It sets up an xinetd service on port 50000 and anything after the trailing slash is treated as a shell command.  So http://<SERVER_IP>:50000/ls generates a directory listing of the current directory.

The port can be changed to whatever port > 1024 you want to use.

1.) Add following line to the end of /etc/services
bashweb      50000/tcp                       # bashweb

2.) nano -w /etc/xinetd.d/bashweb
service bashweb
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/www.bash
log_on_failure += USERID
disable = no
port = 50000
}

3.) nano -w /usr/sbin/www.bash

#!/bin/bash

read request

while /bin/true;
do
read header
[ "$header" == $'\r' ] && break;
done


url="${request#GET }"
url="${url% HTTP/*}"
url=`echo $url | sed 's/\///'`
#url=`echo $url | sed 's/%20/ /g'`
#echo $url;


x=`echo $url | sed "s/\/$//" | awk -F "/" '{print $1}'`
#### Change $y below to your desired password.
#### The URL then looks like this: http://<IP>:50000/PASSWORD/<COMMAND>
y='PASSWORD'

if [ $x = $y ]; then
url=`echo $url | sed "s/\/$//" | awk -F "/" '{print $2}'`
echo -e "HTTP/1.1 200 OK\r"
echo -e "Content-Type: text/plain; charset=us-ascii\r"
echo -e "\r"
$url
echo -e "\r"
else
echo "nope"
fi

4. Set executable permisson

chmod 700 /usr/sbin/www.bash

5.) Restart xinetd

service xinetd restart

Browse to http://<SERVER_IP>:50000/PASSWORD/ls -la
to test
Enjoy!

Kyle