(Optional) Set password-free SSH logon

2024-04-19 08:42:50  Updated

This topic describes how to enable password-free SSH logon.

Terms

  • Central control server

    The server that stores the installation package and cluster configuration information of OceanBase Database.

  • Target server

    The server where you want to install OceanBase Database.

Procedure

To set password-free SSH logon, follow these steps:

  1. Run the following command on the central control server to check whether the key exists:

    ls ~/.ssh/id_rsa.pub
    

    If yes, you do not need to generate a new private SSH key.

  2. (Optional) Run the following command on the central control server to generate public and private SSH keys:

    ssh-keygen -t rsa
    
  3. Copy and paste the public keys to the authorized_keys file on the target server:

    ssh-copy-id -i ~/.ssh/id_rsa.pub <user>@<server_ip>
    

Appendix: sample scripts

We recommend that you use the following script. To run this script, you must have the sudo privilege.

#!/usr/bin/bash
   
SERVERS=("<user>@<server_ip1>" "<user>@<server_ip2>" "<user>@<server_ip3>")
PASSWORD="******"
keygen() {
sudo yum -y install expect
expect -c "
   spawn ssh-keygen -t rsa
   expect {
      *(~/.ssh/id_rsa):* { send -- \r;exp_continue}
      *(y/n)* { send -- y\r;exp_continue}
      *Enter* { send -- \r;exp_continue}
      *(y/n)* { send -- y\r;exp_continue}
      *Enter* { send -- \r;exp_continue}
      eof {exit 0}
   }
   expect eof
"
}
copy(){
expect -c "
   set timeout -1
   spawn ssh-copy-id $1
   expect {
      *(yes/no)* { send -- yes\r; exp_continue }
      *password:* { send -- $PASSWORD\r; exp_continue}
      eof {exit 0}
   }
   expect eof
"
}
ssh_copy_id_to_all(){
keygen ;
for host in ${SERVERS[@]}
do
      copy $host
done
}
ssh_copy_id_to_all

Note

You must replace the SERVERS list and PASSWORD in the first two lines of the script with your own actual server list and password.

Contact Us