Tech

Guides
 

Editing remote files securely with vim

By Vincent Danen, TechRepublic
Monday, February 13, 2006 10:44 AM
Vincent Danen demonstrates how to edit files remotely and securely using vim with SSH.
Often, the life of a sysadmin consists of editing little configuration files here and there, and often on a remote system.

Typically, a sysadmin will remotely log into the system, navigate to the file, edit and save it, then log out. A much simpler and quicker method of accomplishing the same task can be done with vim, without logging into and out of the remote system, provided you have SSH access.

For instance, to edit the file /home/joe/somesite.com/html/index.php, you could use:

<code>
$ vim scp://joe@host//home/joe/somesite.com/html/index.php
</code>


This will use scp to download the file, fire up vim locally to edit it, and upon saving the file, scp it back to the remote host. The basic syntax of the command is:

<code>
$ vim scp://user@host/[path_to_file]
</code>


Note the forward slash (/) delimiter between the hostname and the file name. Once you fill in the path, it will be preceded by a double forward-slash. If the file is in your home directory, this can be shortened to:

<code>
$ vim scp://joe@host/~/somesite.com/html/index.php
</code>


If you use this often, a simple wrapper shell script will ease the typing:

<code>
#!/bin/sh
vim scp://joe@host/${1}
</code>


If you use this script, be sure to enclose the filename in quotes if you use the tilde (~) character to represent home directory; otherwise, your shell will expand it and pass it on to the script already expanded, which could cause havoc if your home directory on the local machine is /Users/joe but is /home/joe on the remote system. Place the shell script somewhere in your path, perhaps as ~/bin/vimhost and then execute it as:

<code>
$ vimhost "~/somesite.com/html/index.php"
</code>



WORTHWHILE?

0

0 votes
Blog

Talkback 0 comments

There are currently no comments for this post.


Guest user

Guest user

Level: 
Joined: —
Already a member? Log in »



 

Loading...

Whitepapers/Case Studies

Downloads

Open Source News



Tech Jobs Now!

Tags

  1. apache software foundation
  2. canada
  3. fedora project
  4. gnome
  5. linux
  6. linux distribution
  7. mandriva
  8. mysql
  9. open source
  10. operating systems
  11. password
  12. red hat inc.
  13. repository
  14. security
  15. server
  16. ssh
  17. tool
  18. ubuntu
  19. vincent danen
  20. web