I'm configuring VIM to execute a rsync
after saving a file, synchronizing my server with my dev laptop. It doesn't work because rsync prompts for my password, even if I've already set up a public key login. How to fix this?

- 167,457
- 16
- 250
- 324

- 51,090
- 44
- 144
- 286
-
2`I'm configuring VIM` ... Can you show what you have done so far? – hek2mgl Apr 22 '13 at 06:15
-
@hek2mgl :nnoremap
':w! ' . ':!rsync -r -e ssh ~/Folder/* user@my_ssh_server.com:~/Folder/ & ' . ':!osascript ~/applescripts/chromereload.scpt & '
4 Answers
If you are using ssh
-connection with rsync
, you can always set up a passwordless connection for it. [Here][1]
are some nice tutorials. It can be done on windows too, via PuTTY, PLink, Pageant, etc. Read the docs.

- 50,406
- 14
- 85
- 110
-
I've already done that, I don't need a password to SSH login on my server, yet it asks some times when I try to rsync. – MaiaVictor Apr 22 '13 at 18:05
Instead of using vim for this, how about using incron? It ships with most modern Linux distributions and will sync any changes, not just those you do in vim.

- 981
- 7
- 10
-
http://stackoverflow.com/questions/1515730/is-there-a-command-like-watch-or-inotifywait-on-the-mac – izak Apr 23 '13 at 08:34
Explicitly define which ssh-key
you are to use with ssh -i
:
:nnoremap <expr> <D-s> ':w!<cr>' . ':!rsync -r -e ssh -i /home/user/.ssh/id_rsa ~/Folder/* user@my_ssh_server.com:~/Folder/ &<cr>' . ':!osascript ~/applescripts/chromereload.scpt &<cr>'
Or you could you try to set your shell variable to interactive, i.e. use ~/.bashrc
++ (man bash
). Not really sure if it has any effect.
:set shell=/bin/bash\ -i
And/or define an alias in your ~/.bashrc
if needed. Maybe combine it with whatever chromereload.scpt
does.
alias vimsync='rsync -r -e ssh -i /home/user/.ssh/id_rsa ~/Folder/* user@my_ssh_server.com:~/Folder/'
More information:
vim -- not recognizing aliases when in interactive mode?
I haven't tried this but it should work:
Put this into your ~/.ssh/config file: ControlMaster auto ControlPath ~/.ssh/cm_socket/%r@%n:%p ControlPersist 300 KeepAlive yes ServerAliveInterval 60
Create the directory ~/.ssh/cm_socket and ssh into the server from another terminal. Now when you ssh into the server again it should use the same socket and no password is required, so your rsync command should work without password.

- 119
- 6