I'm using vim, tmux and zsh. I love those tools. I spent a lot of time to configure those tools, particularly Vim.

In my day-to-day job, I have to access a lot remote machines. I use ssh to be connected with remote servers, Raspberry PIs or virtual machines. For now, every time I access to a new machine, I have to reconfigure all my favourite tools. Most of the time, I just don't use them except for important machines. I cannot only copy my dotfiles, I have also to install some prerequirements.

Is there a way to simplify this process?

  • write a (local) script and execute it on the remote machine: ssh user@server "bash -s" <local_script – Fiximan Aug 13 '15 at 13:36
  • To install and configure all I want ? – Dougui Aug 13 '15 at 13:37
  • are you root on the external machine? use ssh root@server "bash -s" <install_script then log in again as user. (you will auto-logout after the script finishes) – Fiximan Aug 13 '15 at 13:42
  • Can you be clearer. I have to create a script that install all what I need and execute it for each machine I have? – Dougui Aug 13 '15 at 13:44

Assuming you have root access to the machine, you could write an installation routine. I made a few assumptions, as the availability of apt-get

#script, saved local, executed on ssh server:

#install tools:
apt-get -y install tool1 tool2 
#be careful with the -y option, though

#new zsh tools:
#load standard .zshrc file
echo . /home/user/.zshrc > /home/user/.additional_zsh_rc
#add alias
echo alias faster=\'than this long command\' > /home/user/.additional_zsh_rc

#new vimrc
echo "vim settings" > /home/user/.vimrc 

#make sure to change ownerships as we are running this script as root
chown user:user /home/user/.additional_zsh_rc
chown user:user /home/user/.vimrc

Now that we will run the script as root to install

ssh root@server "/bin/zsh -s" <install_script

THEN we can log in as user (after script execution, you are automatically logged out as root). Note that we will have to change our standard rcfile to the new one with -rcs (feel free to change what to source or to change the whole .zshrc file, in my example the new rcfile also sources the standard .zshrc)

ssh user@host "/bin/zsh --rcs /home/user/.additional_zsh_rc"

One could now also put both ssh commands into a script, so you will not need to manually execute them every time. For a hasle-free run, use passwordless ssh-login, but be aware of the dangers, when someone has password-less root access to remote machines after stealing your PC.

  • Is there a non intrusive way? I can be interesting to keep tools without to have to change the machine itself. I will accept your solution if there is not best way. – Dougui Aug 13 '15 at 14:13
  • you mean like executing local executables on the remote machine, as well as using local libraries on the remote machine? Well, if it is just about changing files there, you could mount the whole root directory (or a subset) of the remote machine via sshfs and use all your local settings and programs without the need of installation on the remote machine. – Fiximan Aug 14 '15 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.