Archive for November, 2009|Monthly archive page
Setting up a passwordless login over SSH
Here’s how you can set up a public key to allow you to login to a remote server over SSH without a password. (I draw mainly on the instructions here.)
First, open a terminal on your machine. We’ll call it mybox. We’re going to create a public key.
[me@mybox ~]$ ssh-keygen -t rsa
This will ask you first where you want to save the public key you’re creating. (The default location ~/.ssh/id_rsa is fine.) It will then ask you for a passphrase. You can just press enter twice at those prompts to skip the passphrase (I always have).
Now make sure there is a .ssh directory in the home folder on the server where you want to log in (we’ll call it myserver):
[me@mybox ~]$ ssh me@myserver mkdir -p .ssh
Next we’ll append the public key from mybox to the authorized_keys list on myserver:
[me@mybox ~]$ cat .ssh/id_rsa.pub | ssh me@myserver ‘cat >> .ssh/authorized_keys’
That’s it. You can test it with any command that uses an ssh tunnel (ssh or even svn or git, for example). Also note that you can use this same public key to set up passwordless login on any machine you like.
Now another handy thing is adding preconfigured setups to your ssh config file. It’s located in ~/.ssh/config. Here’s an example setup:
host server
Hostname myserver
User me
(See this reference for explanation on all the possible parameters you can use.)
Now you can type ssh server on the command line and get logged right in–no need to specify your username or enter a password.
Now mind you, this could potentially be a dangerous setup. Only use this on a well-secured computer where you are the only person with access to your terminal. Any hacker that gets in to your machine can now log in as you to myserver without having to know your username or password. Convenience comes at a price.
Sending email through Gmail using PHP
Sending email is often a necessary feature in web applications. Here’s how you can send email from PHP by using SMTP through Gmail.
First, you’re going to need two PEAR packages: Mail and Net_SMTP. Make sure the directory where these files are found is listed in the include_path directive in your php.ini file.
This is based largely on a code snippet from email.about.com. Modify according to your needs. Entries in bold are ones you will definitely need to change.
require_once(‘Mail.php’);
$from = ‘Sender <sender@gmail.com>‘;
$to = ‘Receiver <receiver@something.com>‘;
$subject = ‘Sent from PHP on my machine‘;
$body = ‘This is a message I sent from PHP using the ‘
. ‘PEAR Mail package and SMTP through Gmail. Enjoy!‘;
$host = ’smtp.gmail.com’;
$port = 587; //According to Google you need to use 465 or 587
$username = ‘sender‘;
$password = ‘your_password‘;
$headers = array(‘From’ => $from,
‘To’ => $to,
‘Subject’ => $subject);
$smtp = Mail::factory(’smtp’,
array(
‘host’ => $host,
‘port’ => $port,
‘auth’ => true,
‘username’ => $username,
‘password’ => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo $mail->getMessage();
} else {
echo “Message sent successfully!”;
}
echo “\n”;
?>
Installing Ubuntu in a dual-boot configuration
I’ve installed Ubuntu several times on various machines in a dual-boot format, but I’ve never blogged about it. In all cases, it’s been with Windows on the first partition (mostly with XP, but also once with Vista on a new machine), so I’ll use that as my example here.
First things first. Get Windows ready. This usually includes defragmenting to get all your files at the beginning of the partition. That’s pretty much it.
Next, get the install CD (from Ubuntu or your favorite distribution).
Boot into the installation CD. Ubuntu comes with a partition editor (GParted) on the CD, which you’ll need soon.
Resize your Windows partition in order to leave enough space for (a) the linux system itself, (b) a swap partition if your RAM isn’t plentiful, and (c) any other shared partitions you may want to make:
- (a) In the case of Ubuntu, the minimum hard drive space required is 4 GB, although in my experience at least 10-15 GB is better. This partition will probably be of type ext4 (at least, it is in the latest version of Ubuntu)
- (b) Depending on how much RAM you have and how much hard disk space is available, you may want to add a swap partition. This is a sort of paging file used to swap out segments of the RAM that aren’t used very often, freeing up memory for more active applications. On my old machine, which has 512 MB RAM, I added a 1 GB swap partition. On my current machine with 4 GB RAM, I don’t have any swap space at all and everything runs fine. It’s up to you.
- (c) If you want to be able to share files between Windows and linux (and haven’t yet converted to a cooler solution like Dropbox), it might be wise to make a FAT32 partition that can be read by both operating systems. Make this one however large you need.
Be sure to tell the partition editor that you’re going to want to put the root file system (/) on your ext4 partition, and ensure that your swap partition (if you made one) is correctly identified as such.
If you’ve made it this far, you’re almost done. Now run the installer and let it work its magic.
Ubuntu’s always installed GRUB without a hitch. But if you do run into trouble, this documentation from Ubuntu is a good place to look.
Congratulations, and welcome to linux!
Leave a Comment
Leave a Comment
Comments (1)