My last post explained how I had forgot my password, and had to fix email functionality for Magento on my vagrant box. It turns out I did NOT forget my password, but I used XDebug and discovered that the real problem was:
Fatal error: Uncaught exception 'Exception' with message 'Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct
The reason for this seemed to be permissions, so I chmodded it by editing the vagrant file (thats how you set them when its a shared mount). However for some odd reason (possibly to do with the way PHP does sessions), the session_files were being created but were all 0 bytes in size!
I decided that probably the easiest solution (I tried all the others and they failed! (other than switching to db session storage, I wanted it fixed and to understand!)) would be to save the session data outwith the mounted shared folder (ie outside the site’s root) and instead from /tmp/session.
To do this, in your Magento project, open app/etc/local.xml. You’ll see a line like this:
to change to db storage, change the word files to db. However, to change the ession path, we add another field just below it:
Now that’s done, delete the contents of var/session and var/cache. You should now be able to login! Thank god for that!
Sick of being asked for your password? Set up SSH authorised keys and forget about it!
you@localmachine:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/you/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:
you@localmachine:~> chmod -R go-rwx ~/.ssh
Now copy the contents of /home/you/.ssh/id_rsa.pub, and SSH in for the last time with your password to your remote machine:
you@localmachine:~> ssh email@example.com
Last login: Tue Jan 28 14:14:51 2014 from 18.104.22.168
CentOS release 6.3 (Final)
firstname.lastname@example.org:~> cd .ssh
email@example.com:.ssh> nano authorized_keys
Paste in the contents you copied from your public key file. Make sure it is all on ONE LINE. Save and exit.
firstname.lastname@example.org:.ssh> cd ..
email@example.com:~> chmod -R go-rwx ~/.ssh
you@localmachine:.ssh> ssh firstname.lastname@example.org
Last login: Tue Jan 28 15:28:51 2014 from 22.214.171.124
CentOS release 6.3 (Final)
Want a completely insecure password protected folder using htpasswd? Great!
A pointless exercise unless it’s in a setup at your work and you have no say in the matter, htpasswd’s are sent in unencrypted plain text, so anyone hanging around packet sniffing will pick up the password easily enough! Anyway, thats besides the point, how is it done?
First up we put this in the .htaccess for the directory we wish to protect (ha):
AuthName "My Private Directory"
Then we generate the htpasswd file like this:
htpasswd -c /path/to/htpasswd username
Hooray! The illusion of ‘security’! At least it keeps non geeks out 😉