Change default ssh port number on Ubuntu
Login as the root user or as a user that can execute sudo commands.
#open this file for editing... vim /etc/ssh/sshd_config
Find the line that reads
Port 22
Change this to an different and an available port number…
Port 8000
Next reload ssh
/etc/init.d/ssh reload
You won’t be kicked out of your session. But if you want to open a new connection to your server you need to specify the port number for the connection.
ssh -p8000 root@yourdomain.com
Using sendmail to send mail on ubuntu box
I normally install postfix for my MTA. However, I’ve never really used sendmail so I’d decide to give it a whirl for a new application I’m working on. I don’t use it for anything but handling the mail that the application needs to send out, like new user welcome emails, password resets, etc.
apt-get install sendmail
Sendmail, unlike postfix, won’t work out of the box. Postfix will prompt you for the necessary config setup when running the install. Sendmail won’t, and therefore it’s not ‘out of the box’. You’ll have to make some modifications on your own. Nothing major but this is what I’ve found in order to get it to work, reliably and quickly. The first thing I did was add the fully qualified domain name to my /etc/hosts file
#vim /etc/hosts 127.0.0.1 www.mydomain.com
After this I added the fully qualified domain name to my apache default configuration file
#/etc/apache2/sites-available/default ServerName www.mydomain.com #vhost info etc...
Reload and restart…
/etc/init.d/apache2 force-reload /etc/init.d/sendmail restart
You can test sendmail like so
sendmail email@example.com hello from me .
This should deliver a message to you (the “.” on a new line, followed by a new line, closes the message).
OpenSSL Certificate Generation Information for Certificate Authority to Serve Traffic Over Https
apt-get install openssl openssl genrsa -des3 -out server.key 1024 openssl req -new -key server.key -out server.csr
You’ll be prompted to enter a password (don’t forget it!) as well as fill in company identity information. The most important part is the common name, which is actually the domain you are requesting the certificate for. If you’re going without a wildcard certificate you can specify the subdomain ( secure.seanbehan.com ) otherwise it assumes www.seanbehan.com and seanbehan.com to be the same, and will cover both domains www.seanbehan.com and seanbehan.com… however, it will not cover anything.seanbehan.com. Unless you get a wildcard certificate (these cost more money). Enter company details such as country code, state and the rest are pretty self explanatory.
You need to then submit the server.csr file contents to a certificate authority like godaddy, verisign, etc.
Grab the contents by opening up the file
vim server.csr
After you submit it to them, they then will confirm that everything is correct and then give you the signed certificate back for your use on your server. Unless of course you’re faking your company details and are an evil, wicked spammer!
The certificate authority (CA) should give you instructions for installing the cert, as well as other files so that you can serve secure pages w/out any browser troubles!
Install Sphinx on Ubuntu
It’s a pretty straightforward process. Download the source and compile it. There isn’t a package for it so here are the commands.
wget http://sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz tar xzvf sphinx-0.9.8.1.tar.gz cd sphinx-0.9.8.1/ ./configure make make install
When it’s done nothing fancy happens. You’ll need to test it out w/ an application/ the api.
Chunk an FLV File into Multiple Parts
The format is as follows
ffmpeg -i <input file> -ss <starting point> -t <length of capture> <output file> ffmpeg -i Input_File.flv -ss 00:00:00 -t 00:10:00 Output_Filename.flv
http://www.surfthedream.com.au/blog/Archives/november-2008/how-to-split-a-movie-file-into-multiple-parts
How to Get Your User's SHELL and PATH Information
How to find your user SHELL and PATH on Linux
echo $PATH echo $SHELL
Which will print the paths to the screen
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games /bin/bash
Recursively Zip a Directory and Files on Linux
Short and sweet! Just remember that the finished zip filename is the first argument and the directory you wish to recursively zip comes after.
zip -r name_of_your_directory.zip name_of_your_directory
Add User Directories to Apache2 Web Server
You can either link up the modules yourself like this:
ln -s /etc/apache2/mods-available/userdir.conf /etc/apache2/mods-enabled/userdir.conf ln -s /etc/apache2/mods-available/userdir.load /etc/apache2/mods-enabled/userdir.load
Or you can use the Apache utility
a2enmod userdir
Just remember to restart the server with
/etc/init.d/apache2 force-reload
Also, keep in mind that by default, the home directory for your user will need to require a public_html directory.
/home/username/public_html
Rails, SSL, Ubuntu, Apache2 with Phusion on Ubuntu
Here are all the commands for setting up your Rails application to server requests over SSL -on Ubuntu, of course.
There are great resources and tutorials at these websites.
http://www.tc.umn.edu/~brams006/selfsign.html
http://www.tc.umn.edu/~brams006/selfsign_ubuntu.html
https://help.ubuntu.com/7.10/server/C/httpd.html#https-configuration
The first thing, of course, is that you need OpenSSL installed.
apt-get install openssl
Once you have it installed, you can use this program to generate certificates. The generation process is interactive. It will prompt you for your name, company details, domain etc. It will also prompt for a passphrase for your certificate. Remember this because you’ll be prompted for it when restarting your webserver. If your doing this to test things out, you can make stuff up. If you are doing this for real, and will eventually want to have a certificate authority (CA) validate your generated certs, this information needs to be accurate. This is the purpose of a CA, to validate the identity of companies using certificates!
openssl genrsa -des3 -out server.key 1024 openssl rsa -in server.key -out server.key.insecure openssl req -new -key server.key -out server.csr openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
The program will output certificate files. I assumed you were in your home directory when you generated them. It doesn’t really matter where they are located, but for purposes of organization, let’s move them to a location that makes sense.
cp server.crt /etc/ssl/certs cp server.key /etc/ssl/private
We’ll need to install two modules for apache to use Rails over SSL. If you don’t have them installed already, run these commands.
sudo a2enmod ssl sudo a2enmod headers
The headers module for apache lets us pass the https:// protocol to our Rails application so that it knows to use https.
The next step involves creating a VirtualHost that is listening on port 443. Port 443, is the standard port that https:// runs on.
#create your virtual host on port 443
NameVirtualHost *:443 <VirtualHost *:443> ServerName secure.example.com DocumentRoot /var/www/secure_website/public SSLEngine On RequestHeader set X_FORWARDED_PROTO "https" #***note*** some tuts mention the +CompatEnvVars options here... ignore it b/c it doesn't work SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire #you'll recog these paths, where we stored the certs here SSLCertificateFile /etc/ssl/certs/server.crt SSLCertificateKeyFile /etc/ssl/private/server.key #force app into production mode... RailsEnv production </VirtualHost>
You’ll also need to tell Apache to listen on port 443, if SSL module is loaded. This logic should be included out of the box. Take a look in /etc/apache2/ports.conf. If you don’t see Listen 443, wrapped in a conditional if mod statement… add Listen 443 to that file.
Force a complete reload of Apache so your certs and modules will be loaded.
/etc/init.d/apache2 force-reload /etc/init.d/apache2 restart
You’ll want to restart your Rails application as well.
cd path/to/rails/root/app #if using phusion passenger touch tmp/restart.txt
Now visit your website https://my-ssl.example.railswebsite.com (or whatever it is) and confirm that it is working. You’ll be forced to add an exception to your browsers security checks for the domain that is running a self signed certificate. Add the exception and test out your Rails application.


