In Linux, copy files remotely using scp-Linux Enterprise Application-Linux server application information. The following is a detailed description. Use "scp" to copy an object
SSH provides instructions and shell for logging on to the remote server. By default, it does not allow you to copy files, but still provides a "scp" command.
Suppose you want to copy a file named "dumb" in the current directory of the Local Computer to your home directory on the remote server www.foobar.com. The name of your account on the remote server is bilbo ". You can use this command:
Scp dumb bilbo@www.foobar.com :.
Copy the file back and use this command:
Scp bilbo@www.foobar.com: dumb.
"Scp" calls SSH to log on, copy the file, and call SSH to close the connection.
If your "~ The/. ssh/config file has already configured www.foobar.com as follows:
Host * fbc
HostName www.foobar.com
User bilbo
ForwardAgent yes
Then you can replace "bilbo@www.foobar.com" with "fbc", and the command is simplified to "scp dumb fbc :.".
"Scp" assumes that your home directory on the remote host is your working directory. If you use a relative directory, it is relative to the home directory.
The "-r" parameter of the "scp" command allows recursive directory copying. "Scp" can also copy files between two different remote hosts.
For more information about SSH, see the http://www.linuxaid.com.cn/engineer/brimmer/html/ssh.htm
Http://blog.chinaunix.net/u/8983/showart.php? Id = 55609
Http://www.unix206.com/8/166189.html
Scp command
The scp command is the most convenient and useful command in SSH. Just use the scp command to directly transfer files between two servers. You can run it as root on a server # scp servername:/home/ftp/pub/file1. in this way, the file/home/ftp/pub/file1 on the other server is directly transferred to the current directory of the machine. Of course, you can also use # scp/tmp/file2 servername: /boot sends/tmp/file2 files on the local machine to the/boot directory of another machine. The entire transfer process is still encrypted using SSH.
Use openssh to remotely execute commands --- automatically download apache Log Files
Application. Everything is an application!
This article introduces two points: one is to use ssh to directly log on to other machines (no password is required), and the other is to configure apache to automatically switch log files at intervals. This is all introduced through an example of autosftp. sh. v2 script.
Use openssh to remotely execute commands --- automatically download apache Log Files
I. Preparations
Objective: To automatically download apache logs from multiple machines to a local machine for analysis
Background:
1. There are three web hosts, web1 web2 web3 are solaris systems
2. The local machine traffic is linux 7.3.
3. The entire process requires automatic execution without manual intervention.
4. Consider using Secure ssh protocol to transmit log files
Ideas:
1. Configure the ssh tool between traffic and web host to log on directly
2. Configure apache on the web host to automatically switch logs every day without writing logs to the previous day.
3. Execute a script on traffic to automatically compress the log files on the web host, and then download the files to the local device.
4. Run the local command traffic to decompress the downloaded log file.
II. Implementation Process
1. Configure the ssh tool between traffic and web host to log on directly
1.1 edit the traffic hosts file to add web host entries
Screen Display (to generate a public key file and so on, press enter all)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/. ssh/id_rsa ):
Enter passphrase (empty for no passphrase ):
Enter same passphrase again:
Your identification has been saved in/root/. ssh/id_rsa.
Your public key has been saved in/root/. ssh/id_rsa.pub.
The key fingerprint is:
D1: 69: 34: 80: 56: 2a: 2d: df: 70: 2d: 10: ac: 63: 5e: 1e: 1c root @ web
After 1.3 is generated, copy the local id_rsa.pub to the remote./ssh directory and change the name to authorized_keys2.
Sftp root @ web1
Sftp web1
Connecting to web1
Root @ web1's password: (enter the password)
Sftp>
Sftp> cd. ssh
Sftp> put id_rsa.pub authorized_keys2
Uploading id_rsa.pub to/. ssh/authorized_keys2
1.4 test successful
Scp web1:/usr/local/apache2/logs/hoho/root/copy remote hoho files to the local/root/. ssh directory without entering a password
Hoho 100% 40KB 40.2KB/s)
1.5 addendum or annotation
A. When you log on to web1 for the first time, ssh will prompt you to add web1 to your know_hosts.
B. Direct login verification distinguishes users. The authorized_keys2 file is divided into users.
2. Configure daily automatic switch log files for web hosts
Add the following two sentences to the configuration file. If there is a VM, add it to the configuration of the VM.
CustomLog "|/usr/local/apache2/bin/rotatelogs/usr/local/apache2/logs/mytestsite-access_log. % Y % m % d 86400" combined
TransferLog "|/usr/local/apache2/bin/rotatelogs/usr/local/apache2/logs/mytestsite-access_log. % Y % m % d 86400
3. Script automatically executed on traffic
#! /Bin/bash
# This script is for auto download the log life of apache
# Editor anwei, green
# Version 2.0
# Add 2 parameters GateWay & LogFile
# Add more information for debug
# Add The starting time & the ending of time
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.