演示ssh三种连接方式(密码 公钥 私钥)

1 修改ssh配置文件

演示机: windows kali

今日目标:

  • 对windos linux ssh进行配置
  • 普通密码登录
  • 使用公钥登录
  • 使用私钥登录
  • 使用vscode连接
  • 使用tabby(ssh软件)连接

准备工作:

1,kali linux重新配置ssh(重装)

1.1 ssh卸载重装 (非必要为了演示从无到有)

先停止ssh服务
systemctl stop ssh
apt-get remove openssh-server openssh-client --purge -y &&
apt-get autoremove -y &&
apt-get autoclean -y &&
apt-get install openssh-server openssh-client -y

1.2 删除原有配置文件

rm -rf ~/.shh

1.3 生成公钥 私钥

cd ~
#创建 .ssh文件夹
mkdir .ssh
#给 .ssh文件夹赋予当前用户(读写执行)权利
chmod 700 .ssh
cd .ssh
#生成公钥 私钥 一路回车
ssh-keygen
touch authorized_keys
chmod 600 authorized_keys

1.4 linux 文件权限说明

  • 所有者 当前登录的用户 root

  • 用户组 当前登录的用户所在的分组 可以理解成和root用户一组中的所有用户

  • 公共 所有组的所有用户

  • 例子 chmod 777 hello.txt

  • 7 = 1 + 2 + 4 (读 写 执行) 777 对应 所有用户都可以对hello.txt(读 写 执行)

┌──(root㉿HAC)-[~]
└─# ls -lah
drwx------ 12 root root 4.0K  8月  5 15:13 .config
-rw-r--r--  1 root root   35  8月  5 14:17 .dmrc
-rwxrwxrwx  1 root root    0  8月 16 14:11 hello.sh

ls -lah 查看当前目录下面文件的详细(权限 大小 日期)
d --> dir   表示是一个文件夹
r --> read  表示具有读的权限
w --> write 表示具有写的权限
x --> 猜测是execute 表示具有执行的权限 就是可通过 ./hello.sh 直接运行

1.5 修改ssh的配置文件

vim /etc/ssh/sshd_config
添加4行
PasswordAuthentication yes #普通密码登录
PermitRootLogin yes #允许root登录
RSAAuthentication yes # 开启私钥登录
PubkeyAuthentication yes #开启公钥登录
service ssh start 或者 systemctl start ssh
systemctl status ssh #查看ssh状态

┌──(root㉿HAC)-[~]
└─# systemctl status ssh    
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: disab>
     Active: active (running) since Tue 2022-08-16 13:32:06 CST; 44min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 3988 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 3989 (sshd)
      Tasks: 1 (limit: 4555)
     Memory: 1.5M
        CPU: 53ms
     CGroup: /system.slice/ssh.service
             └─3989 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

2,windows 配置ssh

2.1 电脑已有ssh跳过此步骤

快捷键 win + i 打开设置

2.2 开始配置ssh

powershell/cmd
cd C:\Users\23691\.ssh
# 生成公钥 私钥 一路回车 有一处输 y
ssh-keygen

2 ssh三种登录方式

2.1 普通密码登录

powershell/cmd
#远程主机地址:192.168.1.53
#22 ssh服务端口

第一次连接 ssh root@192.168.1.53 -p 22
C:\Users\23691\.ssh
λ  ssh root@192.168.1.53 -p 22
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
#输入yes
Warning: Permanently added '192.168.1.53' (ECDSA) to the list of known hosts. 
#初次连接会在在"C:\Users\23691\.ssh\known_hosts"产生一条连接记录
root@192.168.1.53's password:
#输入远程主机的密码
Last login: Tue Aug 16 13:32:14 2022 from 192.168.1.3
┌──(root㉿HAC)-[~]
└─#
#成功连接远程主机

第二次连接 ssh root@192.168.1.53 -p 22

C:\Users\23691\.ssh
λ  ssh root@192.168.1.53 -p 22
root@192.168.1.53's password:
#输入密码
Last login: Tue Aug 16 14:47:47 2022 from 192.168.1.3
┌──(root㉿HAC)-[~]
└─#
#成功连接

实操截图

2.2 公钥登录

2.2.1 windows上传公钥

windows上传公钥
进入.ssh目录
cd C:\Users\23691\.ssh
将windows的公钥(id_rsa.pub) 上传至 linux中的 /root 文件夹下
scp "C:\Users\23691\.ssh\id_rsa.pub" root@192.168.1.53:/root/
输入密码

linux 
cd /root
ls

操作截图

2.2.2 将windows的公钥复制到authorized_keys中

linux 开两个终端
将刚刚上传的windows公钥复制到/root/.ssh/authorized_keys中

操作截图

2.2.3 进行连接

linux 重启ssh服务
systemctl restart ssh
windows ssh连接
ssh root@192.168.1.53 -p 22
此时无需输入密码即可连接

操作截图

2.3 私钥登录

2.3.1 下载linux的私钥到windows

linux
将/root/.ssh/id_rsa复制到windows
建议放在C:\Users\23691\.ssh中
windows 在C:\Users\23691\.ssh 新建kali53文件(名字随意)
记事本打开kali53
将linux的私钥复制进去

操作截图

2.3.2 在linux中将自己的公钥追加到/root/.ssh/authorized_keys中

cd /root/.ssh/
cat id_rsa.pub >> authorized_keys
cat authorized_keys

操作截图

2.3.3 通过linux的私钥进行连接

linux 重启ssh服务
systemctl restart ssh
windows 通过私钥进行连接
-i 指定 私钥位置
ssh -i "C:\Users\23691\.ssh\kali53" root@192.168.1.53 -p 22
同样不需要输入密码

操作截图

3 通过vscode连接

3.1 下载插件

3.2 配置连接 ssh root@192.168.1.53 -A

3.3 打开远程文件夹

4 安利一款ssh连接软件Tabby

Tabby阿里云盘下载链接
https://www.aliyundrive.com/s/KQATXDZYb

4.1 初次连接

4.2 再次连接

5 致谢

5.1 typora https://typoraio.cn/

5.2 vscode https://code.visualstudio.com/

5.3 七牛云 https://www.qiniu.com/

免费存储30天图片

5.4 csdn

https://blog.csdn.net/qq_19922839/article/details/117488663

https://blog.csdn.net/zy103118/article/details/126222769

https://blog.csdn.net/Mr_aaaa/article/details/121973913

https://blog.csdn.net/qq_35456400/article/details/107836170

https://blog.csdn.net/qq_27727147/article/details/120304936

还有好多,就不一一例举了…

  • 6
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值