Linux operating another server

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).

  1. Generate a certificate on server A.

    ssh-keygen -t rsa
    

    Press Enter to end.

    Two files, and , will /root/.sshbe generated in the directory :id_rsaid_rs.pub

    • id_rsais the private key .
    • id_rs.pubis the public key .
  2. 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.

  3. Log in to server B and append the file to /root/.ssh/authorized_keysthe file.

    cat /root/id_rsa.pub >>/root/.ssh/authorized_keys
    
  4. Modify authorized_keyspermissions.

    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上执行的命令'

Guess you like

Origin blog.csdn.net/qq_37770674/article/details/133376792