Category Archives: Ubuntu/Debian

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.

Howto install htscanner

I have started using Suphp on some of our confixx servers. Suphp hast one big advantage over mod php it executes PHP scripts with the permissions of their owners. Which is extremely useful on multi domain servers. Otherwise you always have the problem that files uploaded via FTP have different permissions than files upload via http. For example plugins uploaded via the wordpress backend or photos via php gallery. One of the big downsides of Suphp for us is that you cannot use .htaccess files for mod rewrite and so on. This is were htscanner comes along this is the description. Allow one to use htaccess-like file to configure PHP. sounds good 🙂 You need to perform the following steps to install htscanner on debian or ubuntu:

1. Download htscanner:

wget http://pecl.php.net/get/htscanner-0.9.0.tgz

2. Unpack the archive:

tar -xzvf htscanner-0.9.0.tgz

3. Install dependencies:

aptitude install php5-dev php-config

4. Change into the htscanner directory:

cd htscanner-0.9.0

5. run phpize

phpize

6. Configure htscanner

./configure --enable-htscanner

7. Then make and make install

make && make install

8. This should have installed htscanner at the end of the install you should see the install path.

9. Create a file to get the htscanner module loaded:

vi /etc/php5/cgi/conf.d/htscanner.ini

10. With the following content:

extension=htscanner.so

11. restart the Apache web server and you can use .htaccess files again.

Ubuntu 10.04 Lucid Window Buttons On The Left

To get the close and minimize buttons back on the right hand side do the following:

1. Press Alt + F2 and enter:

gconf-editor

2. navigate to /apps/metacity/general/button_layout

3. set the key value to:

:maximize,minimize,close

Thats it log out or restart metacity and your buttons should appear back on the right hand side.

Debian Lenny Possible missing firmware /lib/firmware/bnx2-09-4.0.5.fw for module bnx2

If you see this message after running aptitude upgrade with a Kernel update:

W: Possible missing firmware /lib/firmware/bnx2-09-4.0.5.fw for module bnx2

Do not reboot your server or you will be left without any network. Please edit your apt sources.list file and add the non-free repo. For example it could look like this:

deb http://ftp.hosteurope.de/pub/linux/debian/ lenny main non-free
deb-src http://ftp.hosteurope.de/pub/linux/debian/ lenny main non-free

deb http://security.debian.org/ lenny/updates main non-free
deb-src http://security.debian.org/ lenny/updates main non-free

Please edit the line for your standard apt server and for security.debian.org to receive possible security updates. Then run

aptitude update

Now we can install the missing firmware for our broadcom network card:

aptitude install firmware-bnx2

Check if the firmware has been installed correctly:

web99:~# ls -lha /lib/firmware/
total 212K
drwxr-xr-x 2 root root 112 2010-02-01 12:25 .
drwxr-xr-x 11 root root 4.2K 2010-01-20 15:36 ..
-rw-r--r-- 1 root root 104K 2009-08-04 07:00 bnx2-06-4.0.5.fw
-rw-r--r-- 1 root root 101K 2009-08-04 07:00 bnx2-09-4.0.5.fw

We need this version bnx2-09-4.0.5.fw which you can see in the reported error message above.

Thats it you can carry on and reboot your server.

Ubuntu Karmic mount Windows partition as user

With Ubuntu versions prior to Karmic you could mount windows partitions as a normal user. After typing in the root password you could allow the user to mount a windows partition after ticking the box remember this the user could do this himself in the future. Easy going that’s how it should be with Ubuntu for some reason that does not work any more. And this is the solution:

1. Create a file named:

vi /var/lib/polkit-1/localauthority/50-local.d/nautilus.pkla

2. Copy the following content into the file:

[Allow users to mount with nautilus]
Identity=unix-group:simon
Action=org.freedesktop.devicekit.disks.filesystem-mount-system-internal
ResultAny=no
ResultInactive=no
ResultActive=yes

That’s it easy once you know how it’s done.

Ubuntu Karmic change CPU Frequency as user

With Ubuntu versions prior to Karmic you could change the CPU Frequency as a normal user. After typing in the root password you could allow the user to change the CPU Frequency after ticking the box remember this the user could do this himself in the future. Easy going that’s how it should be with Ubuntu for some reason that does not work any more. And this is the solution:

1. Create a file named:

vi /var/lib/polkit-1/localauthority/50-local.d/gnome-cpufreq.pkla

2. Copy the following content into the file:

[Allow users to set the CPU frequency]
Identity=unix-group:simon
Action=org.gnome.cpufreqselector
ResultAny=no
ResultInactive=no
ResultActive=yes

That’s it easy once you know how it’s done.

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');