1. Basic environment
Server operating system: Microsoft Windows Server 2019 Datacenter Edition
Server software version: OpenSSH_for_Windows_8.6p1, LibreSSL 3.3.3
Server IP address: 192.168.1.100
Client operating system: Microsoft Windows 10 Professional Edition 10.0.19042
Client software version: OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
2. Operation steps
1. [Generate certificate] Operate on the server side:
C:\Users\YangQun>ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\YangQun/.ssh/id_rsa):<按回车键取默认值>
Enter passphrase (empty for no passphrase):<按回车键取默认值>
Enter same passphrase again:<按回车键取默认值>
Your identification has been saved in C:\Users\YangQun/.ssh/id_rsa.
Your public key has been saved in C:\Users\YangQun/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:7zY9nauZr1t+3VqP8DjZPfvs+2idt6xxy06apuWRHR8 yangqun@YangQun-PC
The key's randomart image is:
+---[RSA 4096]----+
| |
| |
| |
| |
| S E |
| . o +|
| ...O.B*|
| .o BX#BX|
| ..oX&@&#|
+----[SHA256]-----+
C:\Users\YangQun>
After executing this command, you will find two files in the C:\Users\YangQun/.ssh/ directory, where id_rsa is the private key (equivalent to a key) and id_rsa.pub is the public key (equivalent to a lock).
2. [Add trust] Operate on the server side and add the contents of id_rsa.pub to PROGRAMDATA /ssh/administrators_authorized_keys. (The specific files need to be viewed in the last two lines of ssh_config)
3. Copy id_rsa to any location on the client and execute the following commands to log in remotely.
ssh -i .\id_rsa -l administrator 192.168.1.100
#或者
ssh -i .\id_rsa [email protected]
You can connect directly without entering a password.
4. Use the following command to directly copy local files to the server.
scp -i .\id_rsa 文本文档.txt [email protected]:D:\
Note: scp does not have the -l option, you can only use @ to separate the user account and host name. If the port number is not the default 22, you need to use -P to specify the port number. P must be uppercase.