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"