Use vim to securely edit remote files

Source: Internet
Author: User
Tags scp command
Article Title: Use vim to securely edit remote files. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Generally, the job of a system administrator is to edit the file configuration on a remote system. Generally, the system administrator needs to remotely log on to the server, debug the file, edit and save the file, and then exit. We can use vim to complete the same task. This method is simpler and quicker, and remote login is not required. Assume that you have the SSH permission.

For example, to edit the file/home/joe/somesite.com/html/index.php, you can use the code:
$ Vim scp: // joe @ host // home/joe/somesite.com/html/index.php


Use the scp command to download the file, use vim to edit it locally, save the file, and upload it back to the remote server. The basic syntax of this command is: $ vim scp: // user @ host/[path_to_file]

Note that the (/) symbol should be placed between the host name and the file name. A double slash (//) can be used when a file path is required (//). For example, if the file is in a local path, the statement can be abbreviated as: $ vim scp: // joe @ host /~ /Somesite.com/html/index.php


If you use such a statement frequently, you can use wrapper shell script. This makes the input easier. Statement:
#! /Bin/sh
Vim scp: // joe @ host/$ {1}

If you use this program and use ~ Character to replace the main directory. Ensure that the file name is placed in brackets. Otherwise, shell will expand the main directory and upload it to the expanded main directory. In this way, the local directory is/users/joe, while the remote server directory is/home/joe. Otherwise, the system will be confused. You can place the shell script in a certain segment of the path and then execute it. For example:
Lt; code>
$ Vimhost "~ /Somesite.com/html/index.php"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.