Sites

Wikipedia
SlashDot
Gentoo Linux
Loop-AES Encryption
Geoiptool
Showing posts with label How To Guides. Show all posts
Showing posts with label How To Guides. Show all posts

Thursday, July 2, 2009

How To Chroot SFTP

Since version 4.8, OpenSSH supports chrooting. This guide will teach you how to lock users to a specific directory which they will not be able to leave(In My Example We Will Be Locking Users To their home directory).

Notes
I will use the user test here with the home directory /home/test. The user test belongs to the group users. I want to chroot the user to the /home directory.

Install OpenSSH
If you do not already have openssh installed please install it now. In Gentoo Issue This command to download and install the latest version of OpenSSH.


emerge -av openssh

Now we need to edit the ssh configuration file to enable SFTP.


nano /etc/ssh/sshd_config

Verify you have this line in the file:


Subsystem sftp /usr/lib/openssh/sftp-server

Then add the following stanza at the end of the file (add one for each user that you want to chroot):


Match User test
ChrootDirectory /home
AllowTCPForwarding no
X11Forwarding no
ForceCommand /usr/lib/openssh/sftp-server

Restart OpenSSH:


/etc/init.d/ssh restart

Now set each Users Home Directory private(unreadable by other users):


chmod 700 /home/test

Thats it Now Load up your favorite SFTP Client and give it a shot. It should
not be possible to leave the /home directory with the user test.

Enjoy..

Bookmark and Share

Understanding Cron Jobs.

Crontab
The command to create/edit, list, and remove cron jobs is crontab. If you call it with the -u option, it specifies the name of the user whose crontab is to be edited. If this option is not given, crontab examines "your" crontab, i.e., the crontab of the user executing the command. If you are looged in as root and run crontab without -u, then root's crontab is listed/modified/removed. If you are logged in as test and run crontab without -u, then test's crontab is listed/modified/removed.

Some Examples:

crontab -l

lists the cron jobs of the user as that you are currently logged in:


test:~# crontab -l
* * * * * /usr/local/examplescript.sh > /dev/null 2>> /var/log/cron.log
30 00 * * * /usr/local/examplescript2.sh > /dev/null 2>> /var/log/cron.log
test:~#

crontab -u exampleuser -l (lists all cron jobs of exampleuser.)

crontab -e (let's you create/modify the cron jobs of the user as that you are currently logged in.)

crontab -u exampleuser -e (let's you create/modify the cron jobs of exampleuser.)

crontab -r (deletes all cron jobs of the user as that you're currently logged in.)

crontab -u exampleuser -r (deletes all cron jobs of exampleuser.)

Cronjob Syntax



A cron job consists out of six fields:

minute, hour ,day of month, month day of week, YourCommand

field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)


When specifying day of week, both day 0 and day 7 will be considered Sunday.

A field may be an asterisk (*), which always stands for first-last.

Names can also be used for the "month" and "day of week" fields. Use the first three letters of the particular day or month (case doesn't matter), e.g. mon or MON for Monday or aug / AUG for August.

Lets look at these examples:


* * * * * /usr/local/example.sh > /dev/null 2>> /var/log/cron.log

This means: execute /usr/local/example.sh > /dev/null 2>> /var/log/cron.log once per minute.

30 00 * * * /usr/local/cron_daily.sh > /dev/null 2>> /var/log/cron.log

This means: execute /usr/local/cron_daily.sh > /dev/null 2>> /var/log/cron.log once per day at 00:30h.

You can also use ranges to define cron jobs:

Examples:

1,2,5,9 - means every first, second, fifth, and ninth (minute, hour, month, ...).

0-4,8-12 - means all (minutes, hours, months,...) from 0 to 4 and from 8 to 12.

*/5 - means every fifth (minute, hour, month, ...).

1-9/2 is the same as 1,3,5,7,9.

Ranges or lists of names are not allowed (if you are using names instead of numbers for months and days - e.g., Mon-Wed is not valid).

1,7,25,47 */2 * * * command

means: run command every second hour in the first, seventh, 25th, and 47th minute.

Instead of the first five fields, one of eight special strings may appear:


string meaning

@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".



Bookmark and Share

Wednesday, July 1, 2009

Mod Rewrite Explained...

In this tutorial, I'm going to be teaching what mod rewrite is and few examples of its uses. Mod rewrite is a powerful tool and one of the simplest ways to make your website more SEO friendly.

So lets get started...

What is Mod Rewrite?

Mod rewrite is a part of apache servers that can rewrite requested URLs on the fly. As it supports an endless number of rules that in turn have unlimited attached rule conditions it is very flexible and an important URL manipulation mechanism. It can be used for internet users and for search engine friendly URLs. This increases the chance of the database driven website to be indexed. Which is a very good thing for you and your website.


Enabling / Installing Mod Rewrite

The first thing we want to do is make sure that we have mod_rewrite on our server. By default, Apache has mod_rewrite installed, but not enabled. The easiest way to test if mod_rewrite is enabled on your server is to create a .htaccess file in a test directory such as /modrewrite-test/.htaccess and edit it to look like this:



Options +FollowSymLinks
RewriteEngine On

Now to test, attempt to browse to the subdirectory(test). One of two things could happen:
  1. No errors mod_rewrite engine is now enabled.
  2. 500, Internal Server Error If you get this message then mod_rewrite was not installed or enabled on your server
If you found that mod_rewrite was not installed on your server, follow these steps.
  1. Find the httpd.conf file (usually you will find it in a folder called conf, config or something along those lines)
  2. Inside the httpd.conf file uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (remove the pound '#' sign from in front of the line)
  3. Also find the line ClearModuleList is uncommented then find and make sure that the line AddModule mod_rewrite.c is not commented out.
After these steps, restart your apache server:

/etc/init.d/httpd restart
now mod_rewrite should be enabled. Be sure to test mod_rewrite again once apache server has been restarted.

Using Mod Rewrite To Always Remove / And Add WWW

One easily fixed problem that many websites have is duplicate results in search engines. In any given search engine, http://www.yoursite.com/ and http://yoursite.com are two completely different websites. This is a big problem because the content in your website is identified as duplicate content, and that brings your search engine rankings down. Using mod_rewrite, we can fix this issue.

At the top of any .htaccess file, you need to turn Mod Rewrite on. This should always be at the top of your .htaccess file.(You only need to turn Mod Rewrite on once)
Also you need to set your Rewrite Base. This is normally the directory in which the .htaccess file is located. In this example the .htaccess is located in the root directory:


RewriteEngine On
RewriteBase /

To always add the www to the front of your site, add the following to your .htaccess file located in the root dir(/):

RewriteCond %{HTTP_HOST} ^yoursite.com$
RewriteRule (.*) http://www.yoursite.com$1 [R=301]


Bookmark and Share

Tuesday, June 30, 2009

How To Configure SSH To Use KEY Authentication (example W/Putty Client)

I will explain how you can replace password-based SSH authentication with key-based authentication which is more secure because only the people that own the key can log in. In this example, we're using PuTTY as our SSH client on a Windows system.

Download And Extract Putty, You Need the Full Package, not just putty.exe.
Now Run puttygen.exe

press Generate button, move mouse. Once the keys are generated, type your key passphrase (choose a "hard to guess" one). Save Public key. Save Private key.


Configuring Linux Server

From The Root Shell(Example Using Username sshtest):


adduser sshtest --disabled-password

Now Do the Following:


su sshtest
cd /home/sshtest
mkdir .ssh
chmod 700 .ssh
cd .ssh

Now we need to open authorized_keys2:


nano authorized_keys2

Next cut & paste your public ssh key, on ONE LINE (THIS is very IMPORTANT!!!)

Notes:

Do not add the email@example.com at the end of the line.
Do not add the BEGIN PUBLIC KEY or END PUBLIC KEY.
Do not add the rsa-key-20090614 at the end.
Make sure, there is ssh-rsa at the beginning.

example:
ssh-rsa AAAAB3NzaC1yc2ELAABBJQAAAIBzPeFQv+295iKzuuPF0jE9429pSHVpDwBvAR9EstmYh...



Now set the chmod on the file:


chmod 600 authorized_keys2

Adding The Private key to PuTTY SSH authentication agent

Run the PuTTY SSH authentication agent PAGEANT.EXE. Once loaded it appears in the systray
Right-Click on it, and select Add key. Now Select your private key file, and type in your passphrase when you add the key. The Pageant works as passphrase storage.

Test Putty To Verify It Works

Open PuTTY and connect as sshtest@yourlinuxserver:

Now when you connect it should just drop you to your shell# prompt.

-Enjoy


Bookmark and Share

Installing ProFTPD W/TLS

As we know or should know FTP protocol is very insecure, the username and password are sent over the wire in plaintext form. Which would allow anyone listening in to see that information and then there is nothing stopping them from using this for their own personal gain.

This Guide Teaches you howto install Proftpd (my Favorite FTP Server) with tls support which allows for a sftp session(encrypted ftp basically using OpenSSL).

Notes:

In this tutorial I use the hostname linux.example.com with the IP address 192.168.1.10. These settings might differ for you, so you have to replace them where appropriate.

Installing Proftpd




issue:
emerge -av proftpd

Now you should see something like this, make sure you have
ssl in your proftpd use flags.(use strings in red are enabled)


emerge -av proftpd

* IMPORTANT: 1 news items need reading for repository 'gentoo'.
* Use eselect news to read news items.


These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild N ] net-ftp/ftpbase-0.01-r1 USE="pam" 0 kB
[ebuild N ] net-ftp/proftpd-1.3.2-r2 USE="acl ipv6 ldap ncurses nls pam ssl tcpd -authfile -ban -case -clamav -deflate -hardened -ifsession -kerberos -mysql -noauthunix -opensslcrypt -postgres -radius -rewrite (-selinux) -shaper -sitemisc -softquota -vroot -xinetd" 2,400 kB

Total: 2 packages (2 new), Size of downloads: 2,400 kB

Would you like to merge these packages? [Yes/No]

Type yes and continue

Now that we have proftpd installed with ssl support, we are ready to generate
our certificates.


mkdir /etc/proftpd/ssl
openssl req -new -x509 -days 365 -nodes -out /etc/proftpd/ssl/proftpd.cert.pem -keyout /etc/proftpd/ssl/proftpd.key.pem


Fill out the questions accordingly
And now we you need to edit the proftpd configuration file /etc/proftpd.conf


nano /etc/proftpd/proftpd.conf

Change the Values To Match These Below:

Include /etc/proftpd/tls.conf
DefaultRoot ~
IdentLookups off
ServerIdent on "FTP Server ready."


Now Open /etc/proftpd/tls.conf for editing:


nano /etc/proftpd/tls.conf

And Edit the tls.conf to match this:



TLSEngine on
TLSLog /var/log/proftpd/tls.log
TLSProtocol SSLv23
TLSOptions NoCertRequest
TLSRSACertificateFile /etc/proftpd/ssl/proftpd.cert.pem
TLSRSACertificateKeyFile /etc/proftpd/ssl/proftpd.key.pem
TLSVerifyClient off
TLSRequired on


If you use TLSRequired on, then only TLS connections are allowed (this locks out any users with old FTP clients that don't have TLS support); by commenting out that line or using TLSRequired off both TLS and non-TLS connections are allowed, depending on what the FTP client supports.

Now Restart the proftpd daemon


/etc/init.d/proftpd restart

You Are DONE! now you can go ahead and use your favorite sftp client, I like SecureFX.

Bookmark and Share

Friday, June 26, 2009

HowTo Install Samba Standalone Server

First We need to install Samba. This can be done by hand downloading and
installing each required dependency and compile it all from source. But I must agree
doing the same thing in Gentoo is much easier.



Install Samba


emerge -av samba



This command will then prompt you yes or no to continue. It may list other packages
to be installed that are necessary for samba to function properly.

Edit the smb.conf(samba Config file) :
Remove the # from infront of security = user



# "security = user" is always a good idea. This will require a Unix account
# in this server for every user accessing the server. See
# /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html
# in the samba-doc package for details.
security = user




Close the file and restart Samba:

/etc/init.d/samba restart
Adding Samba Shares

How to add a share that is accessible by all users:


mkdir -p /home/shares/allusers
chown -R root:users /home/shares/allusers/
chmod -R ug+rwx,o+rx-w /home/shares/allusers/

At the end of the config file /etc/samba/smb.conf add the following lines:


[allusers]
comment = All Users
path = /home/shares/allusers
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
writable = yes

Now If you want all users to be able to read and write to their home directories via Samba, add the following lines to /etc/samba/smb.conf:



[homes]
comment = Home Directories
browseable = no
valid users = %S
writable = yes
create mask = 0700
directory mask = 0700


Now restart Samba One More Time:


/etc/init.d/samba restart

Adding And Managing Users


example: adding a user named dave. You can add as many users as you need in the same way, just replace the username tom with the desired username in the commands.


useradd dave -m -G users



Set a password for dave. If the user dave should not be able to log in to the Linux system, skip this step. (If the user is only supposed to have samba access you can skip this):


passwd dave

Now we need to add the user to Samba:

smbpasswd -a dave

Now you should be able to log in from your Windows workstation with the file explorer (address is \\ip.of.linux.server or \\192.168.0.100\dave for dave's home directory) using the username dave and the chosen password and store files on the Linux server either in dave's home directory or any other shares you created.

-Enjoy


Bookmark and Share

Wednesday, June 24, 2009

How To View Current Running Processes

From the command shell you are going to be using the program "ps".
so lets give it a try, to check your current user processes only do this:

ps -u

Which will only display the current user processes.

Now lets see all processes running on the box regardless of the user
running them.

ps -ax

Now you can quickly see what is currently running on you linux machine.


Bookmark and Share

Saturday, June 20, 2009

Howto Deny Countries With Apache & .htaccess

The following script is using blogama.org IP geolocation API to automatically generate Apache .htaccess file to deny or allow specific countries. You can put this script under crontab and the .htaccess rules will be automatically updated. Also, it can update multiple .htaccess files.

Country codes
You need to know the ISO country code you want to deny/allow. The list is available here.

Method without the automated script

Go to:

http://blogama.org/country_query.php?country=CA,US&output=htaccess_deny

Where country is the list or countries, with a comma between them and output is either htaccess_deny or htaccess_allow.

Before You Start

Create a text file named htaccessfile.txt (in the WORKDIR of the script, see below). In that file, put all (existing!) .htaccess files you wish to update. For example:

/var/www/example.com/.htaccess
/var/www/mydomain.com/.htaccess

Script configuration

Edit the Top Section of the Script:
###MODIFY THIS SECTION###
WORKDIR="/root/"
HTACCESSFILE="htaccessfile.txt"
HTACCESSBLOCK="htaccess-blocklist.txt"
TEMPFILE="htaccess.temp"
COUNTRIES="US,CA"
TYPE="allow"
#########################



WORKDIR: is a writable directory where the script will be located.
HTACCESSFILE: is the file where you will put your .htaccess paths.
HTACCESSBLOCK and TEMPFILE: are temporary file that will be deleted at the end of the script execution.
COUNTRIES: is the list of countries you wish to deny/allow, separated with a comma.
TYPE: "allow" or "deny" access to these countries.

#########################
THE SCRIPT
!/bin/bash
###BLOGAMA.ORG###
###MODIFY THIS SECTION###
WORKDIR="/root/"
HTACCESSFILE="htaccessfile.txt"
HTACCESSBLOCK="htaccess-blocklist.txt"
TEMPFILE="htaccess.temp"
COUNTRIES="US,CA"
TYPE="deny"
#########################
#####DO NOT MAKE MODIFICATIONS BELOW#####
cd $WORKDIR
#Get the file from blogama.org API
wget -c --output-document=$HTACCESSBLOCK "http://blogama.org/country_query.php?country=$COUNTRIES&output=htaccess_$TYPE"
for i in $( cat $WORKDIR$HTACCESSFILE ); do
if [ -f $i ]; then
cat $i 2>&1 | grep "COUNTRY_BLOCK_START"
if [ "$?" -ne "1" ]; then #ALREADY IN HTACCESS
sed '/#COUNTRY_BLOCK_START/,/#COUNTRY_BLOCK_END/d' $i > $WORKDIR$TEMPFILE
cat $WORKDIR$HTACCESSBLOCK >> $WORKDIR$TEMPFILE
mv $WORKDIR$TEMPFILE $i
else #NOT IN HTACCESS
cat $WORKDIR$HTACCESSBLOCK >> $i
fi
fi
done
rm -f $WORKDIR$HTACCESSBLOCK

Make sure you make the script executable:
chmod +x whatever_you_called_this_script

Now you can deny access to non-relevant countrys that do not suit
your sites purpose. Or may just be hogging bandwidth for no
reason.

-Enjoy



Bookmark and Share

Tuesday, June 9, 2009

Getting More Functionality From A PS3 W/Gentoo


I know sony has left us in the dark as far as hardware 3d acceleration because they are not allowing us to directly access the graphics hardware. So to still use the ps3 with more functionality you can with the use of another PC. Instead of running the Xwindows Server locally on the ps3, you can run it over ethernet on a PC. To even up that one I use a pc with dual monitor support and attach my 42in LCD TV. Ok so you are thinking how is this going to work? Well Xwindows in linux is the graphic user interface and it can be run on a remote machine, even Xwindows applications can be loaded on a remote Xwindows server without loading the whole Xwinows Theme. So what does this mean u can use the processor and space on the ps3 all while using the graphics card on your PC to display linux on your Windows PC. Forexample you may load firefox from a shell/terminal window from the PS3 and it will load firefox on my Windows PC running this product X-Win32. So I am going to help you with this process, I will not be going into the actual install of Linux on the PS3 this must already have been completed. Read this guide first to get gentoo on your PS3.


First you must download the evalution or Purchase a copy of X-Win32. This Product is great it has 3d hardware acceleration, OpenGL support Full Screen. Install the Xwin32 software once installed you need to creat a new Session in X-Config (X-Win32 Configuration).
Next you want to select SSH from the drop down menu, and give it a name mine is called PS3. Then Click Next,
On the next page it asks for host. This is going to be the ip of your ps3. Normally it will be in the 192.168.x.x range as most routers use this by default. Login and passwd is the user information on the PS3 gentoo box. Make sure you do not use the root account because this can be dangerous. On the Last page select the first in the List LINUX then click Finish. Now you need to make sure you have the XWin32 Server loaded there should be a icon in the system tray next to the time. Right Click on it Highlight My Sessions -> PS3 this should launch a xterm Terminal Window. You Have DONE IT! now u can just issue any command from this window. Issueing the command startx will load the full Graphical GUI and it will be all displayed over the lan onto your Windows PC. Also to Load another Xterm window type, xterm.

One more thing if you are receiving a 'Connection Refused Error' then make sure the sshd server is loaded and running on the ps3 gentoo machine. (On Gentoo, Issue a /etc/init.d/sshd start) To start the sshd daemon.


Have FUN!

Bookmark and Share

Monday, June 8, 2009

Installing Gentoo Linux (x86)

Ok, so lets get down to installing the best linux distro available. Some things we will need:
  • Internet Connection
  • CD/DVD Burner
  • PC
  • Minimum 4GB of Space
  • One Human
Alright now we are ready to rock n roll. Get the gentoo Install CD from HERE.
There is also a list of mirrors available Here.
Burn this onto a blank CD-R and then insert the cd into the PC we are installing
gentoo on.

Make sure the Bios is setup to boot from the CDROM before the HDD's.
The Bios can usually be accessed by pressing one of these keys on bootup:
F1 , F2 , F10 , F12 , del
Usually the bios will say press BLANK to enter setup. That is the key you should press
to enter the bios and change the boot sequence.

Now the PC should boot off the Gentoo Install CD, If its working correctly you should see
This:














Press enter It will continue to boot the Gentoo Install CD.
Once its done booting you need to configure your ethernet card to access the internet, most common cards will be detected on bootup. Issueing the Command:
ifconfig -a should show atleast one ethX interface.

After You have configure your ethernet card and can access the internet you may continue on.

I like to finish the installed from another PC over a ssh terminal.(/etc/init.d/sshd start) This makes it easy to just copy and paste the commands I will be listing. If not you can manually issue them one at a time.
So lets get started.....

Preparing the Disks

Now we are going to partition and format the Disks.
livecd ~ # fdisk /dev/sda  (/dev/sda is the main
harddisk in this case, but it can be different,
forexmple PATA drives are labeled HDx instead of SDx.)


Your Output May Vary
but as you

can see here
this disk has
no partitons yet.




Now we are going to create a 7gigabyte Partition for gentoo.




Now we need to do the same but this time we are creating about a 1Gigabyte Partition
for the swap system. Follow the same steps as above but you will now be specifying a smaller Size and after you will need to issue these commands to change the partition type
to Linux Swap. After follow the steps in the image below, issuing the w saves the changes to the
disk drive.
















Next Step, Create the file systems and activate swap

livecd ~ # mke2fs -j /dev/sda1
(sda1 is the first partition we created)
livecd ~ # mkswap /dev/sda2 && swapon /dev/sda2
(sda2 should be your swap partition)

Mounting the file systems:

livecd ~ # mount /dev/sda1 /mnt/gentoo
livecd ~ #
cd /mnt/gentoo


livecd gentoo # wget http://distfiles.gentoo.org/releases/x86/2008.0/stages/stage3-i686-2008.0.tar.bz2

livecd gentoo #
tar xjpf stage3*
(this extracts the file we downloaded)
livecd gentoo #
cd /mnt/gentoo/usr


livecd usr # wget http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2

livecd usr # tar xjf portage-lat*
(same thing extracting the file)

livecd usr #
cd /
livecd / #
mount -t proc proc /mnt/gentoo/proc
livecd / #
mount -o bind /dev /mnt/gentoo/dev
livecd / #
cp -L /etc/resolv.conf /mnt/gentoo/etc/
livecd / #
chroot /mnt/gentoo /bin/bash
livecd / #
env-update && source /etc/profile
>>> Regenerating /etc/ld.so.cache...


Time To Set Your TimeZone
(Using US/Eastern as an example)


livecd / # cp /usr/share/zoneinfo/US/Eastern /etc/localtime

Now We need to edit the /etc/fstab file,
all we are doing here is replacing the parition
names where there are currently /dev/ROOT,
and /dev/SWAP.

Should look something like this:












Almost done, Now we need to set the root password again
At the prompt type passwd root, then enter your desired
password.

livecd #
emerge syslog-ng (this installs syslog)

One last step before we take out the Boot CD and
reboot the PC. We need a bootloader to
load linux and or other OS's.

I think lilo is the easiest to work with so,
issue: emerge lilo this will download
and install the latest version of lilo.

now we need to edit the lilo.conf located in /etc/
nano /etc/lilo.conf


#lilo.conf
boot=/dev/sda
map=/boot/map
install=/boot/boot.b
compact
prompt
timeout=50
image=/boot/vmlinuz
label=Gentoo
root=/dev/sda1
read-only
other=/dev/sdb1
label=win
#end lilo.conf

now save it, and type lilo at the prompt
reboot and remove the CD and you are done.
Now you can move on to installing the
software you want.

Bookmark and Share

Gentoo PS3 Installation Continued

Ok, So now we have Gentoo running on our PS3. Now we can now install extra software, this is done by logging in and opening a terminal window.
From the Root Prompt# you can search for software by name with this command emerge --search package-name-here.
So if we want OpenOffice installed which is a office suite, we would issue this command:
emerge -av openoffice, this will then prompt us to continue with yes or no and it will also display the packages to be installed. This may list other software other then just openoffice which is require for OpenOffice to function. So go have fun!! enjoy your new found PS3 abilities.

Installing Gentoo on the PS3

I Love gentoo, it has to be the best linux distribution available & not to mention the fastest. Gentoo is known for speed mostly, because just about everything you install is compiled from source while being optimized for your specific Hardware. This is not the most user friendly distribution but once you have it configured it is easy to do upgrades/updates. Ok so here we go.
Things you need:
  • cd/dvd burner
  • blank disc
  • WIRED internet connection (wireless can be enabled after OS install)
Get the Gentoo Install CD Here
First Burn the ISO to the CD. Then Insert it into the drive.

Now you need to partition the ps3 harddrive to your liking which is dependent on how much space you require for the GameOS and Linux. This can be any of the options except All Space Reserved for GameOS(This would leave nothing for linux)
Now boot the game OS on the PS3, goto Settings ---> System Settings ---> Install Other OS
At this point the Ps3 should read the gentoo boot cd and install the bootloader.

After this is done, select Default OS Option from the System Settings Menu and select Other OS.
It will prompt you to boot the other OS now, select yes.

Now the ps3 should reboot and show a boot: prompt, press enter
Once finishes loading and you are at the root# prompt issue these commands one at a time.

First we Partion the Drive and Format it under Linux:
We are creating 2 partions one for the applications and storage the other for swap space.(In linux the swap space is created into a seperate partion on the harddrive instead of a file like windows uses.
livecd ~ # fdisk /dev/ps3da

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK
(1-1305, default 1305): +9000M

+9000M = 9GB or 9 gigabytes of space for the linux os.
Here we create the swap partition:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1096-1305, default 1096):
Using default value 1096
Last cylinder or +size or +sizeM or +sizeK
(1096-1305, default 1305):
Using default value 1305

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82
(Linux swap / Solaris) This changes the partition
type for swap.
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p

Disk /dev/ps3da: 10.7 GB, 10737414144 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/ps3da1 * 1 1095 8795556 83 Linux
/dev/ps3da2 1096 1305 1686825 82 Linux swap / Solaris

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
livecd ~ #

Now its time to format the OS partition and the swap.

mkfs.ext3 -j /dev/ps3da1  (formats the Linux OS partition as EXT3)
mkswap /dev/ps3da2 (formats Swap Partition)
swapon /dev/ps3da2 (enables the Swap Partiton)

Ok now its time to get ready for the os to install, enter these commands one at a time
at the command prompt.

livecd ~ # mount /dev/ps3da1 /mnt/gentoo/
livecd ~ # cd /mnt/gentoo/
livecd ~ # wget http://gentoo.osuosl.org/experimental/ppc64/
stages/stage4-970-ps3_32ul.tar.bz2
the above command downloads a portion of the OS.
livecd ~ # tar -xjpf stage4*
livecd ~ # mount -t proc none /mnt/gentoo/proc
livecd ~ # mount -o bind /dev /mnt/gentoo/dev
livecd ~ # cp /etc/resolv.conf /mnt/gentoo/etc
livecd gentoo # chroot /mnt/gentoo/ /bin/bash
livecd / # env-update && source /etc/profile
livecd / # export PS1="(chroot) $PS1"
--- 'profiles/arch.list' is empty or not available.
Empty portage tree?
>>> Regenerating /etc/ld.so.cache...
Now we update the database of applications and software for Gentoo
(chroot) / # emerge --sync
After issuing this command it will download all the newest
Ebuilds(instruction files used by the software manager emerge)


Set the timezone

You first need to select your timezone so that your system knows where it is located. Look for your timezone in /usr/share/zoneinfo, then copy it to /etc/localtime. Please avoid the /usr/share/zoneinfo/Etc/GMT* timezones as their names do not indicate the expected zones. For instance, GMT-8 is in fact GMT+8.

(chroot) ls /usr/share/zoneinfo (Suppose you want to use GMT)
(chroot) cp /usr/share/zoneinfo/GMT /etc/localtime
the command ls lists a directory
the command cp copys a file
e2label /dev/ps3da1 /
Now we need to edit the bootloader config file
(chroot) / # cd /etc
(chroot) / # nano kboot.conf

Here is my Kboot.conf( only options that need to change is the
resolution this dependson the TV set you are using,
This is the format)
label='device:
initrd=device: kernel_options'
here is a list of different tv options
# 480i = ps3fb:mode:1
# 576i = ps3fb:mode:6
# 720p = ps3fb:mode:3
# 1080i = ps3fb:mode:4
# 1080p = ps3fb:mode:5
My kboot.conf:
default=gentoo

timeout=5
#This LINE BELOW SHOULD BE ALL ON ONE LINE!!!
gentoo='ps3da1:/boot/kernel initrd=ps3da1:/boot/initrd
root=/dev/ram0 real_root=/dev/ps3da1 init=/linuxrc
video=ps3fb:mode:1 rhgb'

#end kboot.conf

Ok now edit the /etc/fstab file with this command,
nano /etc/fstab

Change it to look like this:
# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't
# needed; notail increases performance of ReiserFS (at the expense of storage
# efficiency). It's safe to drop the noatime options if you want and to
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

#


# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
#/dev/BOOT /boot ext2 noauto,noatime 1 2
/dev/ps3da1 / ext3 noatime 0 1
/dev/ps3da2 none swap sw 0 0
/dev/cdrom /mnt/cdrom audo noauto,ro 0 0
#/dev/fd0 /mnt/floppy auto noauto 0 0

# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
# POSIX shared memory (shm_open, shm_unlink).
# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will
# use almost no memory if not populated with files)
shm /dev/shm tmpfs nodev,nosuid,noexec 0 0
none /spu spufs defaults 0 0

Now we need to set the root password
type passwd root then enter your password


Exit the chroot, unmount filesystems, and reboot

You can now exit the chroot in order to reboot. Be sure to unmount the filesystems prior to rebooting.

(chroot) etc # exit
# cd /mnt/ livecd mnt
# umount gentoo/proc/ gentoo/dev/ gentoo/ livecd mnt
# umount /mnt/usb/ livecd mnt
# reboot

Eject the Install CD when the PS3 power-cycles.

On Reboot Linux should load, Login with User : root and the password you picked.

First we need to edit your make.conf, this is located in /etc/

nano /etc/make.conf , Will open the file to be edited to exit the editor after finishing

press ctrl+x and say yes to saving the file. Here is my example make.conf for the PS3:

CFLAGS="-O2 -pipe -mcpu=970 -mtune=970 -mabi=altivec"
CXXFLAGS="-O2 -pipe -mcpu=970 -mtune=970 -mabi=altivec"

CHOST="powerpc-unknown-linux-gnu"

USE=" curl xml xmlreader apache2 cgi force-cgi-redirect php5 usb -cups altivec X fbcon ps3 gnutls opengl dbus jpeg png gnome eds esd
ssl spell glitz svg gtk gtk2 alsa oss hal truetype ldap fam server"

ACCEPT_KEYWORDS="~ppc ~ppc64"

#end make.conf



Then Issue a emerge --update --deep world

That will then download compile and upgrade all installed packages on your PS3