Linux配置SSH连接方式

1. SSH介绍

1) 什么是SSH
SSH是一种安全协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全

2)SSH服务端和客户端
SSH服务端是一个守护进程,一遍为sshd进程,在后端运行并响应来自客户端的请求。
SSH客户端常用的有BvSsh,SecureCRT,putty等。

3)基本工作机制

  • 客户端发送一个请求到服务端
  • 服务端做数据验证,如包及ip地址等,在发送一个秘钥给ssh客户端
  • 客户端再将密钥发回服务端,自此建立连接

2. ssh密钥登录

1) 首先在服务器中创建密钥对

[root@localhost .ssh]# ssh-keygen -t rsa
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:+LTzDddLCyrFVb9bHRMnOssHgOGJbffji/NV5/hPAEA [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|        .+E      |
|       +....  o..|
|      . = ...o oo|
|       o . .=. o.|
|      . S. oo+. B|
|       o .o.oo.*+|
|        +.. +.= =|
|        .o.* = * |
|         .+o+ o +|
+----[SHA256]-----+

在创建的过程中会提示输入密码,在次不用输入,直接回车即可,创建的密钥对默认放当前登录用户的家目录下的.ssh目录中。

2)在服务器中安装公钥

[root@localhost .ssh]# cat id_rsa.pub >> authorized_keys
[root@localhost .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub

注:此处特别要注意文件名称不能错误(包括大小写), 存放公钥的文件名为: authorized_keys。多个用户多需要登录linux,每个用户都需要密钥,则可以只用上面的追加命令直接将多个用户的公钥直接追加进去即可。

3) 设置文件权限

[root@localhost .ssh]# chmod 600 authorized_keys
[root@localhost .ssh]# chmod 700 ~/.ssh
  1. 设置ssh的配置文件
[root@localhost .ssh]# vim /etc/ssh/sshd_config

修改如下的配置:

# 加密算法
RSAAuthentication yes

# 使用密钥进行认证
PubkeyAuthentication yes

5)重启ssh服务

[root@localhost .ssh]# systemctl restart sshd
  1. 拷贝私钥到PC端(注意:是私钥 id_rsa),使用软件导入秘钥,然后测试登录

xshell配置如下:

bitvise配置:

点击出现如下图: 

猜你喜欢

转载自blog.csdn.net/qq_62898618/article/details/127716635