使用密码登录
C:\Users\xxx> ssh 登录用户名@服务器地址
免密登录 --- 使用公钥登录
C:\Users\xxx> ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\xxx/.ssh/id_rsa):
Created directory 'C:\\Users\\xxx/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\xxx/.ssh/id_rsa
Your public key has been saved in C:\Users\xxx/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:Ld9c5vIbqUFLtYBspVdX8xsSojCKz1Ww/UkW3xB5+IA xxx@StarRain
The key's randomart image is:
+---[RSA 4096]----+
| +.. oo+=.+|
| . . *..E+=+oo|
| . . o o=ooo=o.|
| o . o+..o.oo|
| o S .oo +. |
| o = = . |
| . * + |
| = . |
| . o. |
+----[SHA256]-----+
打开 C:\Users\xxx\.ssh\id_rsa.pub 文件拷贝里面的内容,登录linux服务器,将拷贝的内容写入linux服务器的 ~/.ssh/authorized_keys 文件中。
后续登录就不需要输入密码了。
使用别名登录
打开文件 C:\Users\xxx\.ssh\config, 添加一下内容:
Host 别名
HostName 服务器ip地址
PreferredAuthentications publickey
IdentityFile 密钥地址(是密钥不是公钥)
User 登录用户名
登录服务器:
C:\Users\xxx> ssh 别名