Category Archives: Gentoo

Howto Create a self signed SSL certificate

This howto shows you howto create a self signed SSL certificate without a passphrase. Using openssl with one single command:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.crt

After you have answered all the questions you should have two files one key file and one crt file. Please make sure to enter your domain name when asked for your common name. This can also be an ip address if you don’t have a domain name to use. You can change how long the cert is valid for by changing the value days. If you prefer to have your cert and key in one file normally called a pem file please use the following command:

openssl req -x509 -nodes -days 1095 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

As you can see the only thing i changed is instead of using two file names one for the key and one for the cert. You just repeat the first name which will create the cert and the key in one file called mycert.pem in our example.

Gentoo Linux php 5.3 upgrade

In Gentoo Linux from PHP 5.2 and onwards quite a few things have changed. It is now possible to have a slotted installation of PHP to help people to upgrade to PHP 5.3 and larger. I won’t take the time to explain everything because the Gentoo Dev’s have made a great attempt in creating the PHP Admin Guide. Please read this guide before you attempt the upgrade. Unless you server is a non production system and you don’t care about downtime:

Gentoo Upgrading PHP

X11 Forwarding with SSH

This is fairly simple stuff but it took me 15 minutes to solve because i was missing a package ūüôĀ So i thought i would write a quick article here we go X11 forwarding with ssh. This should work on any Linux distribution unless ssh has been built without the support for X forwarding. Which as far as i know is uncommon.

1. Install xauth with your package manager for ubuntu/debian do

aptitude install xauth

2. Edit the sshd_config on the server you want to start the X program from

vi /etc/ssh/sshd_config

3. Add the following to your sshd_config file on the server

X11Forwarding yes

4. Restart the ssh server

/etc/init.d/ssh restart

5. Edit the ssh_config on the client (this could also be in your home directory under .ssh/config)

vi /etc/ssh/ssh_config

6. Add the following to your ssh_config file on the client

ForwardX11 yes

7. Connect to the server with ssh

ssh user@host

8. You can also use ssh -X user@host Which switches on X Forwarding for the single connection. We don’t need this option because we set it permanently in the ssh_config on the client.

Useful Mysql Commands

when you see  a # it means use the command from the unix shell. When you see mysql> it means from a MySQL prompt after logging into MySQL.

To login (from unix shell) use -h only if needed.

# [mysql dir]/bin/mysql -h hostname -u root -p

Create a database on the sql server.

mysql> create database [databasename];

List all databases on the sql server.

mysql> show databases;

Switch to a database.

mysql> use [db name];

To see all the tables in the db.

mysql> show tables;

To see database’s field formats.

mysql> describe [table name];

To delete a db.

mysql> drop database [database name];

To delete a table.

mysql> drop table [table name];

Show all data in a table.

mysql> SELECT * FROM [table name];

Returns the columns and column information pertaining to the designated table.

mysql> show columns from [table name];

Show certain selected rows with the value “whatever”.

mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";

Show all records containing the name “Bob” AND the phone number ‘3444444’.

mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';

Show all records not containing the name “Bob” AND the phone number ‘3444444’ order by the phone_number field.

mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444' order by phone_number;

Show all records starting with the letters ‘bob’ AND the phone number ‘3444444’.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';

Show all records starting with the letters ‘bob’ AND the phone number ‘3444444’ limit to records 1 through 5.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444' limit 1,5;

Use a regular expression to find records. Use “REGEXP BINARY” to force case-sensitivity. This finds any record beginning with a.

mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";

Show unique records.

mysql> SELECT DISTINCT [column name] FROM [table name];

Show selected records sorted in an ascending (asc) or descending (desc).

mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;

Return number of rows.

mysql> SELECT COUNT(*) FROM [table name];

Sum column.

mysql> SELECT SUM(*) FROM [table name];

Join tables on common columns.

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;

Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password'));
mysql> flush privileges;

Change a users password from unix shell.

# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new-password'

Change a users password from MySQL prompt. Login as root. Set the password. Update privs.

# mysql -u root -p
mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');
mysql> flush privileges;

Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.

# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start

Set a root password if there is on root password.

# mysqladmin -u root password newpassword

Update a root password.

# mysqladmin -u root -p oldpassword newpassword

Allow the user “bob” to connect to the server from localhost using the password “passwd”. Login as root. Switch to the MySQL db. Give privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to bob@localhost identified by 'passwd';
mysql> flush privileges;

Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges;

or

mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;

To update info already in a table.

mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';

Delete a row(s) from a table.

mysql> DELETE from [table name] where [field name] = 'whatever';

Update database permissions/privilages.

mysql> flush privileges;

Delete a column.

mysql> alter table [table name] drop column [column name];

Add a new column to db.

mysql> alter table [table name] add column [new column name] varchar (20);

Change column name.

mysql> alter table [table name] change [old column name] [new column name] varchar (50);

Make a unique column so you get no dupes.

mysql> alter table [table name] add unique ([column name]);

Make a column bigger.

mysql> alter table [table name] modify [column name] VARCHAR(3);

Delete unique from table.

mysql> alter table [table name] drop index [colmn name];

Load a CSV file into a table.

mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' (field1,field2,field3);

Dump all databases for backup. Backup file is sql commands to recreate all db’s.

# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql

Dump one database for backup.

# [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql

Dump a table from a database.

# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql

Restore database (or database table) from backup.

# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql

Create Table Example 1.

mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));

Create Table Example 2.

mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default 'bato');

Devils and Penguins Save Taz

linux.conf.au 2009: Tuz

Impact: help prevent extinction of species

The Tasmanian Devil is a shy iconic Australian creature named for its
spine-chilling screech.  It is threatened with extinction due to a
scientifically interesting but horrific transmissible facial cancer.

This one is standing in for Tux for one release using the far less-known
Devil Facial Tux Disguise.

Save The Tasmanian Devil  tassiedevil.com.au

This is what he looks like:

20090318tuz

How to install grub on a HP Proliant Server

This on took me a while to solve. I got a new server from HP a Proliant DL 380 G5. So i went about installing my favorite distro on it gentoo. So far so good until i reached the step to install grub. Grub would not recognize the hard drives on the smart array controller. This is what i did to fix the problem

E dit the file /boot/grub/device.map to look like this

(fd0) /dev/fd0
(hd0) /dev/cciss/c0d0

Run grub like this:

/sbin/grub --batch --device-map=/boot/grub/device.map --config-file=/boot/grub/grub.conf --no-floppy

grub shell:

grub> root (hd0,0)
grub> setup (hd0)
grub> quit

That’s it your done go compile your kernel or something ūüôā

Gentoo gnome automatic keyring loading

When you log onto a gnome session in ubuntu your gnome keyring automatically gets loaded. So that you can use your WPA or ssh keys in your gnome session. On a gentoo install you get prompted to type in your password to unlock you keyring. So you have to type in your password twice this about how to stop this behavior and pass on your login from gdm to the keyring manager. You must edit a few files in /etc/pam.d

On a gentoo ~x86 system i had to edit the following files all changes i had to make are highlighted in bold text. Please follow the exact order of the statements they are important to make this work.

/etc/pam.d/system-auth

#%PAM-1.0
auth required pam_env.so
auth optional pam_gnome_keyring.so
auth sufficient pam_unix.so try_first_pass likeauth nullok
auth required pam_deny.so

account required pam_unix.so

password required pam_cracklib.so difok=2 minlen=8 dcredit=2 ocredit=2 try_first_pass retry=3
password optional pam_gnome_keyring.so
password sufficient pam_unix.so nullok md5 shadow use_authtok
password required pam_deny.so

session required pam_limits.so
session optional pam_gnome_keyring.so auto_start
session required pam_unix.so

/etc/pam.d/gdm

#%PAM-1.0
auth optional pam_env.so
auth optional pam_gnome_keyring.so
auth include system-auth
auth required pam_nologin.so
session optional pam_gnome_keyring.so auto_start
account include system-auth
password include system-auth
session include system-auth

/etc/pam.d/passwd

#%PAM-1.0
password optional pam_gnome_keyring.so
auth include system-auth
account include system-auth
password include system-auth

/etc/pam.d/gnome-screensaver

#%PAM-1.0
# Fedora Core
auth optional pam_gnome_keyring.so
auth include system-auth
account include system-auth
password include system-auth
session include system-auth

# SuSE/Novell
#auth include common-auth
#account include common-account
#password include common-password
#session include common-session

Source Gentoo forum:

vmware Server /tmp is full and all vms are shutdown

One of our gentoo vmware servers crashed and stopped all running VMs on the server. After looking trough the logs i found out that vmware server had filled the /tmp partion which was 1GB. What i didn’t know is that vmware requires the /tmp partion to¬† be equivalent to 1.5 times the amount of memory on the host. Otherwise you will experience vm crashes. To change the tmp location edit

/etc/vmware/config

and add the following line tmpDirectory = “/<your>/<new>/<tmp>/<directory>”

Be sure that the specified directory is on a local hard drive and that the user running the VMware software has write permissions for that directory. For more infos check out

http://www.vmware.com/support/gsx3/doc/intro_sysreqs_host_gsx.html