Use scp, ssh, etc. without entering a password, scpssh

Source: Internet
Author: User

Use scp, ssh, etc. without entering a password, scpssh
You do not need to enter a password when using scp or ssh.
Echo scp-r root@132.12.22.35:/www/applog/backlog> exp2.sh
Echo scp-r/home/oracle root@10.10.252.5:/www/back/backdmp> exp2.sh
Scp-r root@132.12.22.35:/www/applog/backlog // backup log
Scp-r/home/oracle root@132.12.22.35:/www/back/backdmp // backup database
Scp ~ /. Ssh/id_rsa.pub 132.12.22.35:/root/. ssh/authorized_keys
Sometimes we use scp when copying/moving files to another machine, because it is safer. However, if
It is annoying to enter passwords, especially in scripts. However, ssh has another key pair for verification.
. The following describes how to generate a key pair for your reference.
Step 1: generate a key pair. I use the rsa key. Run the command "ssh-keygen-t rsa"
[Root @ test ~] $ Ssh-keygen-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 ):
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:
Root@test.test.com 46: ed: 89: 18: f8: 30: 04: 41: f5: 72: b2: e6: 66: 27: 20: 73
[Root @ test ~] $
During the generation process, the system prompts you to enter the key pair storage location and press enter to accept the default value. Next, you will be prompted to enter 1.
Password different from your password. Press enter to leave it empty. In this way, the key pair is generated.
The Public Key is stored in ~ /. Ssh/id_rsa.pub
Private keys are stored in ~ /. Ssh/id_rsa
Then change the. ssh directory permission and run the command "chmod 755 ~ /. Ssh"
[Root @ test ~] $ Chmod 755 ~ /. Ssh
[Root @ test ~] $
Copy the public key in this key pair to the machine you want to access and save it
~ /. Ssh/authorized_keys
[Root @ test ~] $ Scp ~ /. Ssh/id_rsa.pub test2:/root/. ssh/authorized_keys
[Email = root @ test2's] root @ test2's [/email] password:
Id_rsa.pub 100% 228 3.2 MB/s
[Root @ test ~] $
In this way, we are done. Then, when you access the machine using ssh scp sftp or another type, you do not need to enter a password.
It is more convenient to use on scripts.

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.