How to Restore OwnCloud Password Without an Email

Forgetting your password can be tiresome, especially if you’re the (only) administrator. Owncloud allows you to reset your password via the user-supplied email address, but this does of course only work if you have an email associated with your account.

Furthermore, the system needs to have a mail server configured. Perhaps you don’t, because of some reason, want to have a mail server up and running.

So here’s how you reset your owncloud admin (or user) password the quick and dirty way.

NOTE: This worked for me, at the time of posting. Future versions might not work this way. Please do proper research before looking into my solution. I am in no way responsible for you breaking something. OK?

First, log in as root or make sure you have sudo access. Or at least make sure you are allowed to modify the owncloud files.

cd /var/www/owncloud/core/lostpassword

We will be modifying the password reset function, instead of going into the database. Please back your existing controller.php file up, and understand that you are going to be susceptible to hacking attempts while making the following modifications.

nano controller.php

We want to supply an email to the system by hard-coding it, and then print the password-reset URL to us. OwnCloud will then continue with its own procedures and attempt to mail the password to the email you provide. Essentially we’re printing the link you’re supposed to get via mail. If you leave this modification in place, anyone will be able to gain access to your OwnCloud!

Go to line 48 and on the line below insert (line 48 begins with $email)

$email = “your-email@domain.tld”; //Set email

Then go to line 53 and on the line below insert (line 53 begins with $link, and this is line 53 after you added the previous line.)

echo $link; //Print email reset link (DO NOT LEAVE THIS IN PLACE)

Now go to your OwnCloud, and try to log in. When it fails, click forgot password link, and then enter your username. You should see the password reset URL pop up. Copy, paste, and chose a new password.

Then, enter

nano controller.php

And remove the lines you just added! DO NOT LEAVE THEM IN PLACE.

I found this to be easier than to edit the database.

Cheers!

Configure SSH to Use Keyfiles Automatically

If you have multiple SSH-keys, perhaps a different one to each server, this can make your life a lot easier. Less typing is better.

Or perhaps you are configuring a remote git repository, or access through some other software.

Go ahead and

nano ~/.ssh/config

And add

Host example.com
IdentityFile ~.ssh/yourkey

Change the domain and filename of your key to the proper values.

Stop Apache2 from listening on port 80

I assume you have enabled SSL so the site is accessible via HTTPS.

Assuming you haven’t changed the configuration, go ahead and type

unlink /etc/apache2/sites-enabled/000-default

This would remove the symlink named 000-default, which points to the default vhost found in sites-available. If you have altered the config, make sure to remove any vhost listening on *:80.

This first step is kind of straight-forward. You want Apache2 to stop listening on port 80, you remove any vhost on that port. But that’s not all.

Open up ports.conf

nano /etc/apache2/ports.conf

Comment out (put # at the beginning of the line)

NameVirtualHost *:80
Listen 80

Go ahead and restart the web server and load the changes

service apache2 restart

Now Apache2 should listen on port 443, and 443 only.

Enable HTTPS on Apache2

This would be a quick way to enable HTTPS (SSL) on Apache2.

cd /etc/apache2/sites-enabled
ln -s 001-ssl ../sites-available/default-ssl
nano 001-ssl

Make sure that the vhost configuration is valid. By default it is configured to /var/www. You might want to have some other directory as your document root.

Then run

a2enmod ssl
service apache2 restart

Do leave a comment if you get any errors. Remember to use sudo if you do not have a root shell.