Setting up ssh passwordless login using ssh-keygen

Setting up ssh passwordless login using ssh-keygen

 

-bash-3.2$ ssh-keygen -t rsa 

Generating public/private rsa key pair.

Enter file in which to save the key (/home/haifeng/.ssh/id_rsa): 

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /home/haifeng/.ssh/id_rsa.

Your public key has been saved in /home/haifeng/.ssh/id_rsa.pub.

 

During the process, you will be asked to enter a password. In order to access the ssh process without a password, you can directly press Enter.

 

-bash-3.2$ ls /app/.ssh/ #The current user of the machine will enter the /app directory after logging in. There are three files under .ssh/

id_rsa  id_rsa.pub  known_hosts

           

Copy the public key to the remote machine and find the corresponding .ssh directory

scp id_rsa.pub username@IP of the remote machine:/app//.ssh/authorized_keys

 

If there is no authorized_keys, create touch one yourself

 

Note: For passwordless access to multiple machines, you need to repeat the above steps, copy the  id_rsa.pub generated in the new machine to the remote server, and then on the remote server, enter the .ssh directory under the current directory

 

cat authorized_keys_newly generated file >> authorized_keys

 

That is to say, add the content of the newly generated id_rsa.pub file to the authorized_keys file of the remote server , so that the keys of multiple machines are stored in authorized_keys

 

Write a script on the local machine to operate the remote machine:

ssh -tt IP of remote machine << EOF

 

cd specifies the directory 

 

./myShell.sh

 sleep 5s # can sleep for a few seconds before executing

exit #automatically exit

 

EOF# This should be on a separate line, appear in pairs, and end

 

sleep 5s # can sleep for a few seconds before executing

You can also write some scripts on the machine to execute

 

End of native scripting

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327015355&siteId=291194637