[ssh_chroot_dir] Chroot dir with ssh

Hi all

There’s a new app for YunoHost, ssh_chroot_dir, like the last one, fallback server, it’s not really a standart application. It’s a script to manage chrooted ssh directories for distant users.

First, let me explain the problematic.

We all have to make some backups of our server, me first. But, keep this backups only on our own server is not quite a good idea. What if the hard disk die ? Or worst…
That’s why it’s always a good idea to have a copy of all your backups somewhere else.

So, I imagine 4 solutions to do that:

  • Put an hard disk with all your backups somewhere. But, it’s not so easy to update…
  • Rent a VPS and put in here your backups. It’s quite expensive for not to much space.
  • Use a “cloud” from one of the GAFAM. Do really have I to explain why it’s a bad idea…?
  • Try to convince a friend to share with you a ssh connexion to put your backups in his server. Even if you’re a good friend of him, is he really ready to give a ssh connection to a nerd or a geek ? You know humans have a natural curiosity…

Because the first solution is really not “modern”, and use a server in a datacenter is far away of the idea of self-hosting, let’s think to the last one.

If it’s clear that you can’t give a ssh connection to everyone, what if this ssh connection allow only to go in a given directory with a limited number a commands available ?
What if you can give a directory to a friend, with a limited space available, and where he can’t do anything else than put here his backups ?

That’s exactly what this app proposes, share with your friends a defined part of your own hard disk to allow them to put there what they want.
Like that, now you know where you can put your backups, in the hard drive of one your friends !

With this app, ssh_chroot_dir, you can so create an user, given to it a directory, fix a maximum space available for this user (without partitioning of your hard drive). Then allow this user to connect to this directory, and only to this directory, by ssh or sftp.

This app uses the scripts and functions of chroot_manager to handle the quotas and chroot directories.


Bonjour à tous

Il y a une nouvelle application pour YunoHost, ssh_chroot_dir, comme la dernière, fallback server, ce n’est pas vraiment une application classique. C’est un script pour gérer les dossiers ssh chrooté pour des utilisateurs distants.

Tout d’abord, laissez moi expliquer la problématique.

Nous devons tous faire des sauvegardes de notre serveur et de nos données. Mais, garder ces sauvegardes seulement sur notre propre serveur n’est pas vraiment une bonne idée. Que se passe-t-il si le disque dur meurt ? Ou pire…
C’est pourquoi c’est toujours une bonne idée d’avoir une copie de toutes vos sauvegardes ailleurs.

Donc, je pense à 4 solutions pour faire ça:

  • Mettre un disque dur quelque part avec toutes vos sauvegardes. Mais, ce n’est pas simple à mettre à jour…
  • Louer un VPS et y mettre vos sauvegardes. C’est un peu cher pour peu d’espace.
  • Utiliser un cloud chez l’un des GAFAM. Dois-je vraiment expliquer pourquoi c’est une mauvaise idée…?
  • Essayer de convaincre un ami de partager avec vous une connexion ssh pour mettre vos sauvegardes sur son serveur. Même si vous êtes un bon ami à lui, est-il vraiment prêt à donner une connexion ssh à un nerd ou un geek ? Vous savez que les humains sont naturellement curieux…

Parce que la première solution n’est vraiment pas moderne, et qu’utiliser un serveur dans un datacenter est bien éloigné de l’idée de l’auto-hébergement, réfléchissons à la dernière solution.

Si il est clair qu’on ne peut pas donner une connexion ssh à n’importe qui, qu’en est-il si cette connexion ssh permet seulement d’aller dans un répertoire précis avec un nombre limité de commandes disponibles ?
Qu’en est-il si vous pouvez donner un répertoire à un ami, avec un espace limité, et dans lequel il ne peut rien faire d’autre qu’y mettre ses sauvegardes ?

C’est exactement ce que propose cette application, partager avec vos amis une partie définie de votre disque dur pour leur permettre d’y mettre ce qu’ils souhaitent.
Ainsi, maintenant vous savez où mettre vos sauvegardes, sur le disque dur d’un de vos amis !

Avec cette application, ssh_chroot_dir, vous pouvez créer un utilisateur, lui donner un répertoire, fixer un espace maximum disponible pour cet utilisateur (sans partitionner votre disque dur). Puis, permettre à cet utilisateur de se connecter à ce dossier, et seulement ce dossier, par ssh ou sftp.

Cette application utilise les scripts et fonctions de chroot_manager pour manipuler les quotas et les chroot ssh.

1 Like

And just now, I made an upgrade to limit the cpu usage for distant users chrooted in their directory.
Not really a limit, it’s a priority. Like that, a distant user can’t paralysed your server if you have to used it for yourself.

1 Like

Can I use Digital ocean spaces https://www.digitalocean.com/products/object-storage/ to implement the backup script ? Will Fallback Server script encrypt the backup on it ? And if my server fails, I will just need to copy the backup to newly created server and restore the backup to make the server work again?

So, yes I guess you can use a Digital Ocean space. If there’s only mount you can used. And I think so.

But, currently, there no backup script. Not yet, I’m working on it.
Fallback Server can encrypt your data, if you’ve asking to.

So, you can use Fallback server to make backups of your current server. There no need to this app for fallback server which already used a chrooted directory.
But, you can build a small script to backup your other data and encrypted them, then use this app to store your backups in your digital ocean.

Can you tell me how to encrypt the backup and hashing it before uploading the backup to the remote server?

You can have a look to the function used by fallback_server.
It’s pretty simple

Thanks

Est-ce qu’il est possible de choisir le répertoire qui est mis à disposition ? Et de donner un espace sur un DD externe ?

No, the directory is hardcoded, https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/blob/master/scripts/install#L91

But you can use a mount bind to move this directory on a external HD.
Maybe a symbolic link would work too, never tried that.

Ok. I tried a mount, but didn’t managed :

sudo mount /media/DD2T/Sauvegardes/chroot/chrootuser/ /home/yunohost.app/ssh_chroot_directories/chrootuser/data/
mount:  /media/DD2T/Sauvegardes/chroot/chrootuser n'est pas un périphérique bloc

And I tried with symbolic links too, but when connected with the chrootuser it seems that it can’t open symbolic links :

-bash-4.4$ ls
bin  data  data_sauv  lib  lib64
-bash-4.4$ cd data
-bash: cd: data: No such file or directory
-bash-4.4$

Here data is a symbolic link.

You have to use a mount bind, not a simple mount, in order to mount a directory into another one.

Thanks, it’s working with mount --bind !

Is it possible to change password, and change or add a ssh key after installation ?

You should find ssh_chroot_dir in /opt/yunohost/ssh_chroot_dir, along with a symbolic link named chroot_manager.sh
You can use that script to change passwords and ssh keys as you want.
Use the man to see how to perform that:

/opt/yunohost/ssh_chroot_dir/chroot_manager.sh --help

EDIT: I misread, that’s not going to be a symbolic link, but the original script.
The symbolic link will be in /home/yunohost.app/ssh_chroot_directories/chroot_manager
Use whichever you want though.

Hi! I’ve re-installed ssh_chroot_dir, and it doesn’t work this time. I removed the 2 instances I had already installed, then I removed manually the folder /home/yunohost.app/ssh_chroot_directories. Then I installed the app, and I can’t connect by ssh.
What is strange is that the folder /home/yunohost.app/ssh_chroot_directories/user is empty.
I tried with password or ssh key, impossible to connect. Any idea ? Where can I find logs ?

Edit : solved https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/issues/11.