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.104
as the client
192.168.1.103
as 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 rsa
Then 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 :
sshoff
Can 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