S15DAY14 SSH secret key remote connection

Source: Internet
Author: User
Tags ssh server

1 signing in with a key
1.1 creating a key pair
1.2 Uploading a public key file
1.3 Importing Public key information
1.4 Signing in with a key pair
2 Remote execution commands
2.1 Simple Commands
2.2 Using scripts to execute multiple commands

192.168.1.104as the client
192.168.1.103as a server

1 signing in with a key

1.1 Creating a key pair

Create a user key pair on the SSH client

ssh-keygen -t rsaThen full return.
Two files will be generated in the ~/.ssh directory: id_rsa (private key) and id_rsa.pub (public key)

1.2 Uploading a public key file

Of course, you can also paste the content copy directly

scp ~/.ssh/id_rsa.pub [email protected]168.1.103:~/.ssh/id_rsa.pub_192.168.1.104

1.3 Importing Public key information

Import the public key text in the SSH server
In the server, the public key database for the target user (the user to log on remotely) is located in the ~/.ssh/ directory, and the default file name is authorized_keys .
Note Modify Authorized_keys Permissions

# 如果authorized_keys不存在,则创建它touch ~/.ssh/authorized_keys# 将上传的公钥添加到authorized_keys后面cat ~/.ssh/id_rsa.pub_192.168.1.104 >> ~/.ssh/authorized_keys# 修改authorized_keys权限chmod 700 ~/.sshchmod 600 ~/.ssh/authorized_keys# 查看authorized_keys最后一行tail -1 ~/.ssh/authorized_keys

1.4 Signing in with a key pair

On the client computer, you can log in directly with the command without ssh 192.168.1.103 entering the user name and password.

2 Remote execution commands

Http://www.cnblogs.com/ilfmonday/p/ShellRemote.html

2.1 Simple Commands

Double quotes, must have. If you do not add double quotes, the second command executes locally
Semicolon, separated by a semicolon between two commands

ssh [email protected]192.168.1.103 "cd ~ ; touch ssh.txt"

2.2 Using scripts to execute multiple commands
#!/bin/bashssh [email protected] > /dev/null 2>&1 << sshoff    cd ~    touch autossh.txtexitsshoffecho "done!"

The remote execution of the content is << sshoff sshoff between, and the operation on the remote machine is in it
Note the point :
sshoffCan be arbitrarily modified into other forms
Redirection is intended to not show the remote output.
Before the end, add exit to exit the remote node

S15DAY14 SSH secret key remote connection

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.