enable ssh session using keys instead of password in dokku


We have a Dokku server installation. You can run remote commands to ease up a little bit the administration tasks.
So, to avoid the need to logon the server and run some dokku commands I needed to configure ssh keys.
First, let’s create our keys -if you haven’t yet-

ssh-keygen -t rsa

let’s copy our public key to the clipboard.

cat ~/.ssh/id_rsa.pub | xclip -selection clipboard

you can add the second command to an alias in the file ~/.bash_aliases if you wish

alias cb=’xclip -selection clipboard’

so the previous command would be

cat ~/.ssh/id_rsa.pub | cb

then we can paste our public key to the authorized clients on the server

ssh joe@dokku.me
sudo su
cd /home/dokku/.ssh
cat >> authorized_keys
press CTRL-C

you must prepend your public key (your key starts with the type, ssh-rsa in this case) in the authorized_keys file with the following configuration (this should have been done when installing dokku)

command=”FINGERPRINT=SHA256:qriqw51R00ha3WHe5Zo987APhwxolya3Sv5Dvwm/fqE NAME=\”admin1\” `cat /home/dokku/.sshcommand` $SSH_ORIGINAL_COMMAND”,no-agent-forwarding,no-user-rc,no-X11-forwarding,no-port-forwarding ssh-rsa AAAAB3Nza…


now you can exit the server and run a remote command from your machine

ssh -t dokku@dokku.me apps:list


ubuntu – from 16.04 to 18.04

ubuntu bionic beaver logo

I used Ubuntu 16.04 for as long as I could. It turns out that Dropbox sent me a notification about dropping support for file systems different than ext4.

your Dropbox folder will stop syncing because it’s on a file system or partition that no longer meets the requirements

I thougth I was using ext4 but, since I had enabled encryption on my home folder, in reality I had ecryptfs. So I needed to use another partition if I’d like to continue using Dropbox.
I thought it wouldn’t be so hard to resize my primary partition -since I used LVM- and create another partition with ext4. Well I tried system-config-lvm and kvpm but they both required to boot from a liveusb or livecd distribution since the partition I wanted to resize was my root partition.

So I decided it would be easier, and perhaps better, for me to just upgrade to ubuntu 18.04 LTS.

I wasn’t wrong, the new version feels smoother, faster and a little bit cleaner.

The only hiccups I had were

  • no fullscreen apps (hide menu bar when maximized)
    Although you can install this gnome extension to enable this behavior.
  • HUD is gone
    I used it with gimp a lot -crop, resize, any menu command available just pressing ALT-. Well, there’s also a gnome extension for this.
  • hot corners (to change between applications pointing the mouse to a corner or CMD+W)
    You can use a gnome extension called custom corner as explained in this article.
  • adding custom launchers to dock
  • it doesn’t have a default backup manager (you can install deja-dup as it was the default before)
    > sudo apt install deja-dup
  • i needed support for exfat (it’s where I placed my last backup)
    > sudo apt install exfat-fuse exfat-utils

well, so far I’m very happy with the upgrade.

ubuntu 16.04 – switch from yarn back to npm again

Recently I’ve upgraded jhipster using yarn, but it caused me some issues running a newly created application. I don’t think the upgrade caused the problem but yarn and the way I installed node.

Time ago I installed node, building it from source to have the latest LTS version. Afterwards, I installed yarn following their instructions and adding their repo. In between creating and upgrading projects, something must have gone wrong and I ended up with different incompatible versions of npm installed. Which led to the issue described above.

if i did a

node -v


npm -v

I checked where did it came from

which npm

but i never installed (so i remember) npm through yarn.

I tried removing it with

yarn global remove npm
error This module isn’t specified in a package.json file.

I decided to clean up all the mess and start over again.
First I had to uninstall node (remember I built it from source)

cd ~/Projects/opensource/node
sudo make uninstall

Then remove yarn

sudo apt remove yarn

optionally you could delete all the cache and configuration files

rm -rf ~/.config/yarn

Now we’re ready to install again, but this time it’s easier to add their repos and install and update from them.

install node (LTS)

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash –
sudo apt-get install -y nodejs
node -v
npm -v
which npm

Since jhipster now recommends npm as default, that’s it.

There’s a lot of discussion about npm or yarn, like this on reddit or this article

optionally install yarn

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add –
echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

yarn global upgrade jhipster doesn’t update

I was trying to upgrade jhipster to its latest version in order to update an application that was generated by a previous version of the generator.

Since I use yarn for package management (although it seems i will be getting back to npm), I just tried

yarn global upgrade generator-jhipster

which let me with the same version I had before

jhipster -v

I found the answer here

Keep in mind that upgrade respects semver range specified in package.json. I believe the default location on OSX is ~/.config/yarn/global/package.json

So yarn global add some-package would add a carret-range, something like ^1.0.0 so if a 2.0.0 comes out, yarn global upgrade would not upgrade to that because it doesn’t fit the range. You would specify the –latest/-L flag to ignore the semver range and get the latest as tagged in the registry.

so, in order to update jhipster run the following command

yarn global upgrade generator-jhipster –latest

dokku – move wordpress site with duplicator


about dokku

Docker powered mini-Heroku. The smallest PaaS implementation you’ve ever seen.

Dokku allow us to run an app inside docker containers and scale easily -just like heroku does-

We have a microsite made with wordpress which we wanted to move inside dokku. The first thing you need is to install duplicator in your original website, create a package and build it, download the installer.php and the zip file.

We’ll use the dokku-wordpress script to generate the required files. It has the following requirements

A Dokku server. Tested on 0.7.2+
The dokku-mysql plugin
make installed locally
curl or wget installed locally

To install the dokku-mysql plugin just ssh into the dokku server and run

sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql

Then clone the dokku-wordpress repository to your local machine, run the command and follow the instructions that are printed in the command line from the last command and take note of the DATABASE_URL when you link the database container

git clone https://github.com/dokku-community/dokku-wordpress.git
cd dokku-wordpress
make build APP_NAME=testapp SERVER_NAME=<ip or name>

# run the following commands on the server to setup the app:

dokku apps:create testapp

# setup plugins persistent storage

mkdir -p /var/lib/dokku/data/storage/testapp-plugins
chown 32767:32767 /var/lib/dokku/data/storage/testapp-plugins
dokku storage:mount testapp /var/lib/dokku/data/storage/testapp-plugins:/app/wp-content/plugins

# setup upload persistent storage

mkdir -p /var/lib/dokku/data/storage/testapp-uploads
chown 32767:32767 /var/lib/dokku/data/storage/testapp-uploads
dokku storage:mount testapp /var/lib/dokku/data/storage/testapp-uploads:/app/wp-content/uploads

# setup your mysql database and link it to your app

dokku mysql:create testapp-database
dokku mysql:link testapp-database testapp

# you will also need to set the proper environment variables for keys and salts
# the following were generated using the wordpress salt api: https://api.wordpress.org/secret-key/1.1/salt/
# and use the following commands to set them up:

dokku config:set testapp AUTH_KEY='Q<z4;VJkx#Jd;tV^d?ex^jwM^z/|b.$w,f4x[/vgCSVXKhZ|aO1p,'
dokku config:set testapp SECURE_AUTH_KEY='>zR1uL02;5+pDRA%HEz!~ty])hV^@;-s-`-rk`W+)zfdeWQ&e=yZM.j)M0Q4}xk1'
dokku config:set testapp LOGGED_IN_KEY=':5W#<&PO*_B7<Cj?7aLrbq|8PoF?2ZR.?_DAki*e3Oh!+RM@Ga@q6:L~(p=!D,SyHwa$B5.Fk'
dokku config:set testapp LOGGED_IN_SALT='xv$Lq]/6bowHaMF@Eff5fL/ab,-pu,P,Jh4U{uiIE~>mog<.O9gDW2+!IOo$M*='
dokku config:set testapp NONCE_SALT='dj8^5?t=V-,nV7}-{*bnz7b7vb.=N1:~BrMC`-D{GLl(k[+}!hh#D[tk#TcG;7|'

# now, on your local machine, change directory to your new wordpress app, and push it up

cd testapp
git push dokku master

then you'll have a vanilla wordpress deployed in dokku.

You should have a directory generated in the cloned folder named after your app, get into it and delete all the files except the following (notice there are hidden files)


copy the files downloaded from duplicator inside this folder and deploy doing a git push dokku

open your app's url pointing to installer.php file and follow the instructions. Use the values from the DATABASE_URL generated earlier, if you didn't take note, you can get it by running the command

ssh -t dokku@<ip or name> config <appname>

use that values for the DB configuration step and continue with the setup.
for example if you have the following DATABASE_URL

the corresponding values would be


done! you should have cloned successfully your wordpress site into dokku.

mySQL – encontrar registros si el id esta en una cadena (columna)

En una tabla de wordpress se guarda un registro donde se concatenan los id’s de las imagenes adjuntas a un tipo de post, por ejemplo


para encontrar los posts (de tipo attachment) que corresponden a estos id’s podemos utilizar la función find_in_set de la siguiente manera

select p.post_title, concat('http://localhost/wp-content/uploads/', m.meta_value) image_url
from wptv_posts p 
join wptv_postmeta m on p.id = m.post_id
where 1 = 1 
and m.meta_key = '_wp_attached_file'
and find_in_set(p.id, 
(select m.meta_value
from wptv_posts p
join wptv_postmeta m on p.id = m.post_id
where 1 = 1
 and p.id = 27116
 and m.meta_key = 'image_to_attach'
 )) &gt; 0

en esta consulta utilizamos primero una subconsulta para encontrar la información ‘meta’, del post que nos interesa, donde estan las referencias a los archivos adjuntos y luego buscamos el atributo ‘_wp_attached_file’ para los registros encontrados para formar la ruta a las imagenes mediante la función concat.

Un ejemplo sin la subconsulta sería el siguiente

select p.post_title, concat('http://localhost/wp-content/uploads/', m.meta_value) image_url
from wptv_posts p 
join wptv_postmeta m on p.id = m.post_id
where 1 = 1 
and m.meta_key = '_wp_attached_file'
and find_in_set(p.id, 
'27954,27955,27956,27958,27960,27962,27964,') &gt; 0

La función find_in_set regresa el índice del elemento si lo encuentra en el arreglo de cadena, por ello filtramos los registros en que es mayor a cero (si se encontró).