Server trust
In an operation and maintenance scenario, if one server needs to operate another server, the target server (hereinafter referred to as B server) needs to trust the current server (hereinafter referred to as A server).
-
Generate a certificate on server A.
ssh-keygen -t rsa
Press Enter to end.
Two files, and , will
/root/.ssh
be generated in the directory :id_rsa
id_rs.pub
id_rsa
is the private key .id_rs.pub
is the public key .
-
The public key is copied to server B.
scp /root/.ssh/id_rsa.pub root@B:/root/
Here, since server B does not yet trust server A, it will prompt for a password.
-
Log in to server B and append the file to
/root/.ssh/authorized_keys
the file.cat /root/id_rsa.pub >>/root/.ssh/authorized_keys
-
Modify
authorized_keys
permissions.chmod 600 /root/.ssh/authorized_keys
Server operations
upload files
Use the following command to transfer files from server A to server B.
scp A文件路径 B账号@B地址:B路径
Excuting an order
You can use the following command on server A to operate server B.
ssh -tt B账号@B地址 '在B上执行的命令'