什么是ssh?
SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定;SSH 为建立在应用层基础上的安全协议。SSH 是目前较可靠,专为 远程登录 会话和其他网络服务提供安全性的协议。
如何快速的配置ssh免密登录
配置ssh分三步走
- 在本地创建公私钥
ssh-keygen -t rsa #加密方式选 rsa|dsa均可以,默认dsa
-t #The type of the key to generate 密钥的类型
-C #comment to identify the key 用于识别这个密钥的注释
$ ssh-keygen -t rsa #加密方式选 rsa|dsa均可以,默认dsa -t The type of the key to generate 密钥的类型 -C comment to identify the key 用于识别这个密钥的注释
Generating public/private rsa key pair.
Enter file *in* which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty *for* no passphrase):
Enter same passphrase again:
Your identification has been saved *in* /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved *in* /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:gygJuDyfHDsL3n7HoNxXKNrjelXTKjQ1FgvXBVuoR/g geek@PC-20190414MTRE
The key's randomart image is:
+---[RSA 2048]----+
| . o+.+o |
|. o=.+o |
|o o.*. |
|.o . . + + E |
|.oo.. o S + |
| +.+o + + |
| ..*= = o |
|. o+o* + |
| ..==.+ |
+----[SHA256]-----+
- 用ssh-copy-id 将公钥复制或传输到远程服务器,并将身份标识文件追加到服务器的
$ ssh-copy-id -i ~/.ssh/yuxiangServer.pub usaename@ip
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
"/c/Users/Administrator/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log *in* with the new key(s), to filter
out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- *if* you are prompted
now it is to install the new keys
yuxiangshi@119.23.78.131's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'yuxiangshi@119.23.78.131'"
and check to make sure that only the key(s) you wanted were added.
- 配置本机ssh config文件
Host yuxiangServer
HostName 119.23.78.131
User yuxiangshi
Port 22
PubkeyAuthentication yes
IdentityFile ~/.ssh
- 修改服务器 /etc/ssh/sshd_config,并重启sshd服务
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile ~/.ssh/authorized_keys
愉快的玩耍吧。