Linux SSH Public Key登录与免密登录
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash

·
Linux SSH Public Key登录与免密登录
- ssh 远程登录密码认证的方式有三种,
password
、Keyboard Interactive
、Public Key
前面两种方式就是密码认证,含义都是一样大同小异。第三种是登录方式最安全的一种。接下来就是讨论这种。
原理
- ssh客户端利用服务端发过来的私钥,进行登录的认证,认证服务端的公钥。从而实现安全的访问。
- 这种方式是使用ssh的publickey可以进行免密登录,假设我们要登录的远程服务器为linux,本地可以是windows或者linux都行,操作如下:
两台机器的命令执行
- 打开命令行,执行命令
ssh-keygen
,两台机器都要执行的,windows和linux存放的位置不一样,但是名字是一样的。
jackdan@jackdan-ThinkPad-T430:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:lVbwkC08s+Qh56PrdxfSGYoifBrg7lSbWDinZnfRwI8 root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| .o+. |
| .. X=. |
| o*+*. |
| .. B= . |
| .oo+ E.oo o o |
| .B+o+.. o + |
| .* +=.o . . |
| +..... . . . |
| .. ... . . |
+----[SHA256]-----+
Enter file in which to save the key (/root/.ssh/id_rsa):
默认存储路径;
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
- 两次回车,代表免密登录
ssh文件目录
- 进入上面这个目录,windows目录是
C:/User/.ssh/
这个目录,linux目录是~/.ssh/
这个目录。
jackdan@jackdan-ThinkPad-T430:~/.ssh$ ll
total 44
drwx------ 2 jackdan jackdan 4096 7月 25 14:36 ./
drwxr-xr-x 87 jackdan jackdan 4096 9月 16 16:38 ../
-rw------- 1 jackdan jackdan 1675 7月 10 2018 id_rsa
-rw-r--r-- 1 jackdan jackdan 406 7月 10 2018 id_rsa.pub
...
id_rsa
私钥文件;id_rsa.pub
公钥文件。
本地公钥文件拷贝到远程服务器上
- 将本地的公钥拷贝一份放到远程服务器的下面这个目录(直接动手进行复制,或者
ssh-copy-id -i id_rsa.pub root@10.10.1.2
),将10.10.1.2
换成远程服务器地址。
[root@localhost .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.1.70
[root@localhost .ssh]# ll
-rw-------. 1 root root 408 9月 17 16:27 authorized_keys
...
authorized_keys
存放免密认证电脑的公钥。
免密登录远程服务器
- 最后,你就可以直接登录远程服务器了,使用命令
ssh root@127.0.0.1
,其中把127.0.0.1换成远程服务器的ip
,再补充一下,ssh指定端口号登录ssh -p xx user@ip
,xx为端口号、user为用户名、ip为要登录的ip。
JackDan9 Thanking




A beautiful web dashboard for Linux
最近提交(Master分支:7 个月前 )
186a802e
added ecosystem file for PM2 5 年前
5def40a3
Add host customization support for the NodeJS version 5 年前
更多推荐
所有评论(0)