Winscp uses a key to connect to a linux server and a java program uses a key to connect to a server

1. Winscp connects to the linux server with a key

The first step is to generate the ssh public key key pair:

Use Tera Term to log in to the server (at this time, log in with your username and password first),

#ssh-keygen -t rsa

cd into the /root/.ssh directory:

# cat id_rsa.pub >> authorized_keys

# chmod 600 authorized_keys

Log in to winscp with username and password, enter /root/.ssh, there will be three files

Copy the id_rsa file to the local. At this time, the key file cannot be used. It needs to be converted into ppk format.

 

Re-open winscp without logging in

 

 

select location id_rsa

 

 

 Then there will be an id_rsa.ppk file in the same local directory, which is the available key file.

Then you can use the key to log in to the server

 

 

Then log in, you can log in successfully without a password.

Second, the java program uses the key to connect to the server (the local is the SpringBoot+gradle project, so it is configured in the application.properties file.)

 

The tool to be used is the jsch class, and the maven or gradle project only needs to import the corresponding dependencies

Then start writing the connection code

Get the host address and key file in the configuration file 

 

start connection

 

 

 

 

Guess you like

Origin blog.csdn.net/dazhanglao/article/details/121286292