Scp execution in the Linux background and scp execution in the linux background

Source: Internet
Author: User
Tags scp file scp command

Scp execution in the Linux background and scp execution in the linux background

Recently, it takes a long time for a large scp file to be completely down on a remote machine. After executing the command using xshell, it cannot be closed. Otherwise, it will stop, I cannot keep this xshell. I thought of nohup, but the scp command entered the password is prompted, and cannot write the command. After some searches, it is important to find a good way:

The following is an scp that does not enter a password:

Recently, I encountered a problem in writing a shell with timed Automatic execution. In this step, you need to use the scp command to copy the local file to another machine for backup. However, you usually need to enter the user password after executing the scp command, which is not applicable in the shell step of timed Automatic execution.

My first instinct is to create a user without a password. To use this user in the scp command, you do not need to enter the user password.

For the convenience of discussion, we call the machine that executes the scp command as the Client, and the remote machine operated by the scp command as the Server.

First, run the following command to delete the root password on the Server, even if the root password is changed to a user without a password.

[Root @ Server root] # passwd-d root

Removing password for user root.

Passwd: Success

[Root @ Server root] #

To confirm that the root user has changed to a user without a password, log on to the system and try again.

Red Hat Linux release 8.0 (Psyche)

Kernel2.4.18-14 on an i686

Server login: root

Last login: Fri Sep 14 16:40:08 on tty1

[Root @ Server root] #

It is true that the password is no longer required for root login.

Then, we copy a file from the Client to the Server.

[Root @ Client root] # scp-p text root@192.168.3.206:/root

Root@192.168.3.206's password: <-- press enter directly

Permission denied, please try again. <-- denied

Root@192.168.3.206's password: <-- enter any character

Text 100% | ************************** | 19

[Root @ Client root] #

According to the test results, even if the root user becomes a user without a password, the scp command will prompt you to enter the password during execution. Even more strange is that the press enter is rejected when the password is prompted. However, if you enter any other characters, enter the Enter key to confirm the authentication.

Later, I searched for related information on the Internet. For more information, [1] after the two users of the two machines establish a secure trust relationship, you do not need to enter the user password when executing the scp command. Based on the method described in this document, the test is successful.

Follow these steps to establish a security trust relationship between the root of the Client and the root of the Server:

1. Run the ssh-keygen command on the Client to generate a certificate that establishes a security trust relationship.

[Root @ Client root] # ssh-keygen-B 1024-t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/. ssh/id_rsa ):

Enter passphrase (empty for no passphrase): <-- press Enter

Enter same passphrase again: <-- press Enter

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:

49: 9c: 8a: 8f: bc: 19: 5e: 8c: c0: 10: d3: 15: 60: a3: 32: 1croot @ Client

[Root @ Client root] #

Note: When the program prompts you to enter passphrase, enter the carriage return, indicating no certificate password.

The above command generates the Private Key Certificate id_rsa and Public Key Certificate id_rsa.pub, which are stored in the. ssh subdirectory of the user's home directory.

2. Copy the Public Key Certificate id_rsa.pub to the. ssh subdirectory of the root directory of the Server, and change the file name to authorized_keys.

[Root @ Client root] # scp-p. ssh/id_rsa.pub root@192.168.3.206:/root/. ssh/authorized_keys

Root@192.168.3.206's password: <-- enter the root user password for the machine Server

Id_rsa.pub 100% | *************************** | 218

[Root @ Client root] #

When executing the preceding command, the root user of the two machines has not yet established a security trust relationship, so you also need to enter the root user password of the machine Server.

After the above two steps, the security trust relationship is established between the root of the Client and the root of the Server. Let's take a look at the effect:

[Root @ Client root] # scp-p text root@192.168.3.206:/root

Text 100% | ************************** | 19

[Root @ Client root] #

Successful! You do not need to enter the password any more.

It carries from http://www.lslnet.com/linux/dosc1/30/linux-238181.htm.

Finally, a simple shell is written.

[Root @ usboss bakup] # more aa. sh

Scproot@10.130.38.233:/home/channel/exp_boss_20090626.dmp.gz.

Then run the command in the background.

Nohup bash aa. sh &

OK to solve the problem, ls a few times found that the file has been increasing close shell and then open again, normal transmission.

The next day, I found that all the large files were down. Everything is OK!

××××××××××××××××××××××××××××××××××××××××××× ×

I accidentally saw a good suggestion on the internet today. Update it first:

In the past, when using nohup comd & to convert it to the background for execution, the biggest problem was that scp was a prompt command and could not be completed using a single command. Therefore, the two machines should establish trust, so that it does not need to enter a password. In this way, the establishment of the trust mechanism makes the process complicated. Now there is a way to change the command running on the foreground to the background, so that the scp command will continue to be input in the prompt mode, and then convert it to the background using the method of changing the foreground to the background, it is a good solution to the problems solved in this article. (Haha, in fact, any problem can be divided into several steps. The solution of these steps can also refer to the steps in other problems, so that we can refer to our ability to solve the problem. Ps: I think of a sentence in the article "reading for junior high school students": We didn't eat rice, but we drank water instead of water. At that time, I was particularly impressed by the reading time. I also used it here. We recorded the issue of implementing the scp backend and formed a blog, in fact, the root goal of the long-term goal is not to remember this problem, but to remember the steps that have been taken to solve this problem. In the future, when a certain step is encountered, I can quickly complete it using this problem as a medium, improve the problem solving capability. This is the fundamental purpose .)

Use kill command to go to the background for execution

Use ps-a to locate the process number, and then use sudo kill-stop procNumber to pause the process. Run jobs to check the process to be transferred to the background, find its job number, and then use bg jobNumber to transfer it to the background. Like this:

Ps-

PID TTY TIME CMD

6729 pts/0 00:00:00 mystar

Sudo kill-stop 6729

Jobs

[2] + Stopped sudo mystar

Bg 2

Then you can use fg jobNumber to redirect the process to the foreground.

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.