前言
# 客户端
Windows 10 2004
# 服务器
Ubuntu 18.04 LTS
# cmd
C:\Users\qbit\.ssh> where ssh
C:\Windows\System32\OpenSSH\ssh.exe
直接登录
# cmd
ssh qbit@112.78.9.10
免密登录
证书生成
C:\Users\qbit\.ssh>ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\qbit/.ssh/id_rsa): qbit_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in qbit_rsa.
Your public key has been saved in qbit_rsa.pub.
The key fingerprint is:
SHA256:N+DzINKI2Sua4p3VP8u4HU8MjFO9D6z842+neZnQnoE qbit@qhost
The key's randomart image is:
+---[RSA 2048]----+
| |
| . |
| .. . |
| + o .+.. . |
| o + ooSoo+ o |
| o..o=+.oE o |
| . .. . +.o .o =|
|.o..o =.=. ..B |
|=. o o.=+++++ |
+----[SHA256]-----+
C:\Users\qbit\.ssh> dir
2020/06/14 17:24 <DIR> .
2020/06/14 17:24 <DIR> ..
2020/06/14 12:07 176 known_hosts
2020/06/14 17:24 1,679 qbit_rsa
2020/06/14 17:24 393 qbit_rsa.pub
拷贝公钥到服务器
# bash
mkdir .ssh
- 在 Windows 10 上使用
scp
命令上传公钥
C:\Users\qbit\.ssh> scp qbit_rsa.pub qbit@112.78.9.10:/home/qbit/.ssh
qbit@112.78.9.10's password:
qbit_rsa.pub 100% 393 12.3KB/s 00:00
将公钥追加到 authorized_keys
文件
# zsh
qbit@qhost ~/.ssh
$ ls
qbit_rsa.pub
qbit@qhost ~/.ssh
$ cat qbit_rsa.pub >> authorized_keys
qbit@qhost ~/.ssh
$ ls
authorized_keys qbit_rsa.pub
ssh 客户端配置文件
- 在
C:\Users\qbit\.ssh
目录下创建 config
文件,并添加如下内容
Host aliyun
HostName 112.78.9.10
Port 22
User qbit
IdentityFile C:/Users/qbit/.ssh/qbit_rsa
免密登录
C:\Users\qbit\.ssh> ssh aliyun
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-72-generic x86_64)
本文出自 qbit snap
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。