# Backup and Restore Keybase on Windows 7

John Simpson `<kg4zow@kg4zow.us>` 2018-02-17

I've been running Windows 7 on an old laptop for ham radio purposes. The hard drive started showing signs of degradation, so I picked up a small (240GB) SSD to replace it.

The laptop was running Keybase, and I didn't want to have to add it to my account as a new device after replacing the disk - I wanted to back up the files which contained the machine's Keybase "identity" and restore them on the new SSD, so that it remains the "same" device.

A bit of web searching found a few pages which *kinda* explained which files needed to be backed up and restored, but the best one I found was [https://wiki.chotaire.net/keybase](https://wiki.chotaire.net/keybase). He explains how to back up the four files which actually make up the "identity", and asks that if anybody does this by backing up the entire directory trees, to let him know.

I did this by backing up and restoring the entire directory trees, so I'm writing this up for him, but also as notes to myself in case I need to do this again in the future, and if others find it useful, I'm happy it helps.

## Files to back up

The following files comprise the device's "identity". At the bare minimum, these are the files you need to back up on the old machine.

```
%userprofile%\AppData\Local\username.ss
%userprofile%\AppData\Local\config.json
%userprofile%\AppData\Local\secretkeys.username.mpack
%userprofile%\AppData\Local\session.json
```

However, I found it easier and simpler to just back up both of the following directory trees.

```
%userprofile%\AppData\Local\Keybase
%userprofile%\AppData\Roaming\Keybase
```

* Obviously these files contain sensitive information, including the keys which prove that the device which has them *is* the authorized device on your Keybase account. Wherever you back them up to, needs to be secure. I backed mine up to a [Verarcypt](https://www.veracrypt.fr/) container on a USB stick.

* Note that one of the files contains a session identifier, and sessions time out after a certain length of time. As such, I backed up these directories *just before* shutting the machine down.

## Restore

Once the new disk was installed, I installed and activated Windows. After the seemingly never-ending stream of updates was finished, I installed Veracrypt and mounted the encrypted container containing the backup files.

Then I installed Keybase, and tried the directions on Chotaire's web site. When I tried to delete the two directories it had created, it wouldn't let me, because (1) the tray icon didn't actually *do* anything when I clicked on it, and (2) even after killing the `keybase.exe` and `kbfsdokan.exe` processes, there was still some kind of process in the background with open filehandles within one of the directories. The only way I could get rid of them was to totally un-install Keybase, and even then I had to reboot in order to be able to delete them.

So before Keybase is installed (or after it's been un-installed and you have rebooted), do the following...

* If the following directories exist, rename or delete them:

    ```
    %userprofile%\AppData\Local\Keybase
    %userprofile%\AppData\Roaming\Keybase
    ```

* Restore the two backed-up directories as:

    ```
    %userprofile%\AppData\Local\Keybase
    %userprofile%\AppData\Roaming\Keybase
    ```

* From a command line, run the installer with the following option:

    ```
    keybase_installer_386.exe driver=1
    ```

    When I originally installed Keybase on the laptop, the KBFS functionality would not work until I re-ran the installer with this option. When I installed it on the new SSD, I used the same command and, after finishing the restore process above, KBFS worked just fine.

* When the install finishes, it should connect as the device you originally backed up. If you see a "Login" button, it means that the device was disconnected long enough for the session contained in the `session.json` file to have timed out. Just click the "Login" button and it should connect again without any problems.

**Note:** where you see `%userprofile%` above, this is referring to your "home directory", which is usually something like "`C:\Users\username`". If you're used to dealing with non-Windows operating sytems, this is the Windows notation for an environment variable.
