DEV Community

Serhat Teker
Serhat Teker

Posted on Originally published at tech.serhatteker.com on

Remotely Edit Files on Vagrant

We know we can edit files via scp in Vim as we've seen in: Vim SSH.

$ vim scp://user@host//path/to/file/file.extension
⭐ Must Read: serhatteker/remotely edit files on vagrant me - ประเด็นร้อน ⭐ Must Read: serhatteker/remotely edit files on vagrant me - ประเด็นร้อน

Editing files on vagrant virtual machine is a little bit harder to achieve.

We can ssh into vagrant (along with option vagrant ssh) after adding our ssh public key:

$ ssh -i ~/.ssh/id_rsa.pub -p 2222 vagrant@localhost
⭐ Must Read: serhatteker/remotely edit files on vagrant me - ประเด็นร้อน ⭐ Must Read: serhatteker/remotely edit files on vagrant me - ประเด็นร้อน

More info about this: Add SSH Public Key to Vagrant

However we can't add these flags to scp. So what is the solution then?

The solution is adding ssh config file as we've seen in SSH Config:

Host vagrantlocal
  HostName localhost
  Port 2222
  User vagrant
  IdentityFile ~/.ssh/id_rsa.pub
  PasswordAuthentication no
⭐ Must Read: serhatteker/remotely edit files on vagrant me - ประเด็นร้อน ⭐ Must Read: serhatteker/remotely edit files on vagrant me - ประเด็นร้อน

After that we can remotely edit files:

$ vim scp://vagrantlocal//path/to/file/file.extension
⭐ Must Read: serhatteker/remotely edit files on vagrant me - ประเด็นร้อน ⭐ Must Read: serhatteker/remotely edit files on vagrant me - ประเด็นร้อน

All done!

Top comments (0)