Sharing $HOME folder
seamlessly share a /home/user directory between two Linux computers - ChatGPT
First idea was to share the full ~/ folder through nfs.
- login will be completly stuck if the nfs server is unreachable
- they are some race conditions (not so sure what) when connecting from ssh that made that solution unstable.
And there was also some other drawbacks ⚠️
- ssh keys will be shared ash well
- to be able to connect to other system own key need to be added to ~/.ssh/authorized_keys
- firefox will refuse to start thinking it’s already started
It is advise to enable different config between the two system (missing application / different version)
- consider using a dotfile manager (like chezmoi or yadm) to manage user-specific configs smartly
Now moving to an alternative approach. There are 2 Scenarios to consider
| ~/ | Exec on Host | remote Exec |
|---|---|---|
| .config | chezmoi | same |
| Files | local1 | local2 |
| Folder | autofs | same |
| Nix package | local1 | local2 |
| base system | local1 | local2 |
- Using chezmoi synchronisation is not automatic, but is still easy.
- Folder autofs is cumbersome, but done very few time. It also provide a kind of sandboxing, exposing only what is required for processing on other computer
.config
Using dotfiles and chezmoi - helps you manage your personal configuration files (dotfiles, like ~/.gitconfig) across multiple machines.
- install .dotfile from a git repo on a new empty machine
- easy update
- choose which file are managed by chezmoi
example Adding `~/.config/nix
$ chezmoi add .config/nix/nix.conf`
see also
One other possibility (dismissed)
- kyrat - A simple ssh wrapper script that brings your dotfiles always with you on Linux. kyrat can transfer to the remote host and source the following dotfiles
- bashrc
- Volatile Dotfiles over SSH - discussion about various tools that can be helpfull (lnk) / stow
Files
This can be covered by
- chezmoi but with no automatic synchronisation.
- rsync if prefered
Which file needs to be syncrhonized anyway?
One easy restriction policy is that
~/root is private to each host,- don’t write any shared files there and keep writing to autofs folder for sync
Folder
Any ~/folder can be covered by autofs.
But you have to use direct map Configuration
Working example
Modify auto.master & _auto.yves
# auto.master
# direct map
/- /etc/auto.yves --ghost,--timeout=30# /etc/auto.yves
/home/yves/Documents/ -fstype=nfs,rw,nosuid,nodev yves-huv:/home/yves/Documents/
/home/yves/Videos/ -fstype=nfs,rw,nosuid,nodev yves-huv:/home/yves/Videos/Check that it works
$ sudo systemctl restart autofs
$ ls ~/Documents
$ ls ~/VideosNon working Example
This setup will prevent tools like kitty ssh to work, because nothing can be written on ~/ directly, only mounted folder (~/Documents,~/Videos) are accessible.
If for simplifying configuration we let autofs handle the ~/, it will hide everything except the automounted folder.
Mouting
- ~/Documents → /export/media/docs
- ~/Video → /export/media/videos
Modify auto.master & _auto.yves
# auto.master
/home/yves /etc/auto.yves# auto.yves
Documents -fstype=nfs,rw,nosuid,nodev yves-huv:/home/yves/Documents
Videos -fstype=nfs,rw,nosuid,nodev yves-huv:/home/yves/VideosCheck that it works
$ sudo systemctl restart autofs
$ ls ~/Documents
$ ls ~/VideosFixing IP
To make the /home folder available reachable, ip of the server must be fixed, cf:
- add a 2nd ip for a laptop
- this is dependant of the interface: changing a usb dongle will hide it.
- setup a static ip for a server
Usage
Some example of configuration usage makint usefull to share $HOME hosted on huv (laptop) with lab (more powerfull server).
see Homelab