<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean&#039;s Blog &#187; security</title>
	<atom:link href="http://seanbehan.com/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Adding Public/Private Key Pairs on Mac OS X and Ubuntu for Passwordless Remote SSH Sessions</title>
		<link>http://seanbehan.com/linux/adding-publicprivate-key-pairs-on-mac-os-x-and-ubuntu-for-passwordless-remote-ssh-sessions/</link>
		<comments>http://seanbehan.com/linux/adding-publicprivate-key-pairs-on-mac-os-x-and-ubuntu-for-passwordless-remote-ssh-sessions/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 23:09:42 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=872</guid>
		<description><![CDATA[On your local machine cd into the .ssh directory in your home &#8220;~/&#8221; directory. If it doesn&#8217;t exist you can create it with &#8220;mkdir ~/.ssh&#8221;. Next generate your public/private keys and copy the public key to the remote server. cd ~/.ssh ssh-keygen -t rsa -b 4096 # will take a couple seconds but when finished [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Flinux%2Fadding-publicprivate-key-pairs-on-mac-os-x-and-ubuntu-for-passwordless-remote-ssh-sessions%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Adding Public/Private Key Pairs on Mac OS X and Ubuntu for Passwordless Remote SSH Sessions" data-url="http://seanbehan.com/linux/adding-publicprivate-key-pairs-on-mac-os-x-and-ubuntu-for-passwordless-remote-ssh-sessions/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>On your local machine cd into the .ssh directory in your home &#8220;~/&#8221; directory. If it doesn&#8217;t exist you can create it with &#8220;mkdir ~/.ssh&#8221;. Next generate your public/private keys and copy the public key to the remote server.</p>
<pre class="wp-code-highlight prettyprint">
cd ~/.ssh
ssh-keygen -t rsa -b 4096
# will take a couple seconds but when finished
# specify a full path (if there is already an existing key) or hit enter to install to the default location ~/.ssh
# when it prompts for a passphrase just hit enter
# and enter again when it asks to confirm the passphrase
# then we copy the public key the remote server (this assumes you don't already have an authorized_keys file)
# copy and paste the contents of the id_rsa.pub file into the authorized_keys file otherwise
scp id_rsa.pub user@yourdomain.com:.ssh/authorized_keys
</pre>
<p>You&#8217;ll need to edit your ssh config file and restart the process to allow for public/private key authentication.</p>
<pre class="wp-code-highlight prettyprint">
vim /etc/ssh/ssh_config
# add or uncomment these two lines
RSAAuthentication yes
PubKeyAuthentication yes
# ... and restart
/etc/init.d/ssh restart
</pre>
<h1>Troubleshooting</h1>
<p>A couple of things to keep in mind. 1) Permissions matter. Make sure that your keys are not world readable (this should be secure) Run chmod 400 on authorized_keys file.</p>
<p>If you had a set of keys already setup in .ssh/ on your local machine and want to install the new keys in another directory so as not to overwrite the old pair, you need to add them to ssh with this command</p>
<pre class="wp-code-highlight prettyprint">
ssh-add ~/full/path/to/your/new/keys
</pre>
<p>More information is available here <a href="http://www.debian-administration.org/articles/152 ">http://www.debian-administration.org/articles/152<br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/linux/adding-publicprivate-key-pairs-on-mac-os-x-and-ubuntu-for-passwordless-remote-ssh-sessions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Placing an Authenticity Token in a Rails Form</title>
		<link>http://seanbehan.com/ruby-on-rails/placing-an-authenticity-token-in-a-rails-form/</link>
		<comments>http://seanbehan.com/ruby-on-rails/placing-an-authenticity-token-in-a-rails-form/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 17:04:49 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[authenticity token]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=709</guid>
		<description><![CDATA[&#38;lt;%= hidden_field_tag :authenticity_token, form_authenticity_token %&#38;gt;]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fplacing-an-authenticity-token-in-a-rails-form%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Placing an Authenticity Token in a Rails Form" data-url="http://seanbehan.com/ruby-on-rails/placing-an-authenticity-token-in-a-rails-form/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><pre class="wp-code-highlight prettyprint">
 &amp;lt;%= hidden_field_tag :authenticity_token, form_authenticity_token %&amp;gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/placing-an-authenticity-token-in-a-rails-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change default ssh port number on Ubuntu</title>
		<link>http://seanbehan.com/linux/change-default-ssh-port-number-on-ubuntu/</link>
		<comments>http://seanbehan.com/linux/change-default-ssh-port-number-on-ubuntu/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 16:46:42 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[22]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=499</guid>
		<description><![CDATA[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&#8230; Port 8000 Next reload ssh /etc/init.d/ssh reload You won&#8217;t be kicked out of your session. But if [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Flinux%2Fchange-default-ssh-port-number-on-ubuntu%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Change default ssh port number on Ubuntu" data-url="http://seanbehan.com/linux/change-default-ssh-port-number-on-ubuntu/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Login as the root user or as a user that can execute sudo commands.</p>
<pre class="wp-code-highlight prettyprint">
#open this file for editing...
vim /etc/ssh/sshd_config
</pre>
<p>Find the line that reads</p>
<pre class="wp-code-highlight prettyprint">
Port 22
</pre>
<p>Change this to an different and an available port number&#8230;</p>
<pre class="wp-code-highlight prettyprint">
Port 8000
</pre>
<p>Next reload ssh</p>
<pre class="wp-code-highlight prettyprint">
/etc/init.d/ssh reload
</pre>
<p>You won&#8217;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.</p>
<pre class="wp-code-highlight prettyprint">
ssh -p8000 root@yourdomain.com
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/linux/change-default-ssh-port-number-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Email Obfuscation and Extraction from Text with Rails</title>
		<link>http://seanbehan.com/ruby-on-rails/email-obfuscation-and-extraction-from-text-with-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/email-obfuscation-and-extraction-from-text-with-rails/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 16:50:29 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[hyperlinking]]></category>
		<category><![CDATA[obfuscation]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[recipes]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=423</guid>
		<description><![CDATA[There is a helper method for handling the obfuscation of email addresses in Rails. mail_to &#34;me@domain.com&#34;, &#34;My email&#34;, :encode =&#62; &#34;hex&#34; # =&#62; &#60;a href=&#34;mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d&#34;&#62;My email&#60;/a&#62; If you want to then extract an email address(or all email addresses) from a block of text here is the code. I created a helper function called &#8220;emailitize&#8221; and [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Femail-obfuscation-and-extraction-from-text-with-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Email Obfuscation and Extraction from Text with Rails" data-url="http://seanbehan.com/ruby-on-rails/email-obfuscation-and-extraction-from-text-with-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>There is a helper method for handling the obfuscation of email addresses in Rails.</p>
<pre class="wp-code-highlight prettyprint">
mail_to &quot;me@domain.com&quot;, &quot;My email&quot;, :encode =&gt; &quot;hex&quot;
 # =&gt; &lt;a href=&quot;mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d&quot;&gt;My email&lt;/a&gt;
</pre>
<p>If you want to then extract an email address(or all email addresses) from a block of text here is the code. I created a helper function called &#8220;emailitize&#8221; and put it in the ApplicationHelper module inside helpers/application_helper.rb</p>
<pre class="wp-code-highlight prettyprint">
module ApplicationHelper
  #takes a string and will return the same string but with email addresses encoded and hyperlinked
  def emailitize(text)
    text.gsub(/([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})/i) {|m|
        mail_to(m, m.gsub(&quot;@&quot;, &quot;&lt;small&gt;[at]&lt;/small&gt;&quot;), :encode=&gt;:hex)
    }
  end
end
</pre>
<p>It&#8217;s important to remember that you&#8217;ll need to pass a block to the gsub method. You can&#8217;t do something like this instead</p>
<pre class="wp-code-highlight prettyprint">
text.gsub( /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})/i, mail_to('\\1@\\2', '\\1@\\2', :encode=&gt;:hex) )
</pre>
<p>It will work except the encode will fail. It will evaluate the &#8216;\\1@\\2&#8242; strings rather than as dynamic variables.</p>
<p>You can then use this function in your views</p>
<pre class="wp-code-highlight prettyprint">
&lt;%= emailitize @job.how_to_apply %&gt;
</pre>
<p>More information is available in the Rails and Ruby docs:</p>
<p>http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001887</p>
<p>http://ruby-doc.org/core/classes/String.html#M000817</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/email-obfuscation-and-extraction-from-text-with-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails, SSL, Ubuntu, Apache2 with Phusion on Ubuntu</title>
		<link>http://seanbehan.com/linux/rails-ssl-ubuntu-apache2-w-phussion-on-ubunt/</link>
		<comments>http://seanbehan.com/linux/rails-ssl-ubuntu-apache2-w-phussion-on-ubunt/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 21:21:11 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://bseanvt.wordpress.com/?p=20</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Flinux%2Frails-ssl-ubuntu-apache2-w-phussion-on-ubunt%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Rails, SSL, Ubuntu, Apache2 with Phusion on Ubuntu" data-url="http://seanbehan.com/linux/rails-ssl-ubuntu-apache2-w-phussion-on-ubunt/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Here are all the commands for setting up your Rails application to server requests over SSL -on Ubuntu, of course.</p>
<p>There are great resources and tutorials at these websites.</p>
<p>http://www.tc.umn.edu/~brams006/selfsign.html</p>
<p>http://www.tc.umn.edu/~brams006/selfsign_ubuntu.html</p>
<p>https://help.ubuntu.com/7.10/server/C/httpd.html#https-configuration</p>
<p>The first thing, of course, is that you need OpenSSL installed.</p>
<pre class="wp-code-highlight prettyprint">
apt-get install openssl
</pre>
<p>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&#8217;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!</p>
<pre class="wp-code-highlight prettyprint">
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
</pre>
<p>The program will output certificate files. I assumed you were in your home directory when you generated them. It doesn&#8217;t really matter where they are located, but for purposes of organization, let&#8217;s move them to a location that makes sense.</p>
<pre class="wp-code-highlight prettyprint">
cp server.crt /etc/ssl/certs
cp server.key /etc/ssl/private
</pre>
<p>We&#8217;ll need to install two modules for apache to use Rails over SSL. If you don&#8217;t have them installed already, run  these commands.</p>
<pre class="wp-code-highlight prettyprint">
sudo a2enmod ssl
sudo a2enmod headers
</pre>
<p>The headers module for apache lets us pass the https:// protocol to our Rails application so that it knows to use https.</p>
<p>The next step involves creating a VirtualHost that is listening on port 443. Port 443, is the standard port that https:// runs on.</p>
<p>#create your virtual host on port 443</p>
<pre class="wp-code-highlight prettyprint">
NameVirtualHost *:443

&amp;lt;VirtualHost *:443&amp;gt;

  ServerName secure.example.com
  DocumentRoot /var/www/secure_website/public
  SSLEngine On
  RequestHeader set X_FORWARDED_PROTO &quot;https&quot;
  #***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
&amp;lt;/VirtualHost&amp;gt;
</pre>
<p>You&#8217;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&#8217;t see Listen 443, wrapped in a conditional if mod statement&#8230; add Listen 443 to that file.</p>
<p>Force a complete reload of Apache so your certs and modules will be loaded.</p>
<pre class="wp-code-highlight prettyprint">
/etc/init.d/apache2 force-reload
/etc/init.d/apache2 restart
</pre>
<p>You&#8217;ll want to restart your Rails application as well.</p>
<pre class="wp-code-highlight prettyprint">
cd path/to/rails/root/app
#if using phusion passenger
touch tmp/restart.txt
</pre>
<p>Now visit your website https://my-ssl.example.railswebsite.com (or whatever it is) and confirm that it is working. You&#8217;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.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/linux/rails-ssl-ubuntu-apache2-w-phussion-on-ubunt/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

