Debian开启SSH

一、Debian开启SSH

参考链接:

https://blog.csdn.net/zzpzheng/article/details/71170572

https://help.aliyun.com/knowledge_detail/41486.html

 

树莓派的Debian从8.0开始,默认关闭了SSH。打开的方式如下:

debian 开启SSH

1、修改sshd_config文件,命令为:vi /etc/ssh/sshd_config 

2、将#PasswordAuthentication no的注释去掉,并且将NO修改为YES  //我的kali中默认是yes

3、将#PermitRootLogin yes的注释去掉 //我的kali中默认去掉了注释

4、启动SSH服务,命令为:/etc/init.d/ssh start // 或者service ssh start

5、验证SSH服务状态,命令为:/etc/init.d/ssh status

6. 添加开机自启动   update-rc.d ssh enable
 

关闭则为:

update-rc.d ssh disabled

自启动需要重启生效

 

二、使用SSH命令登录Linux实例失败,使用/etc/init.d/ssh status 验证SSH服务状态时出现“No supported key exchange algorithms”的错误

SSH服务会对相关密钥文件的权限进行检查。比如,私钥文件默认权限是600,如果配置成777等其它权限,导致其它用户也有读取或修改权限。则SSH服务会认为该配置存在安全风险,进而导致客户端连接失败。

  1. 登录实例,参考以下命令,恢复相关文件的默认权限。
    cd /etc/ssh/
    chmod 600 ssh_host_*
    chmod 644 *.pub
  2. 执行ll命令,确认文件权限正常。
    total 156
    -rw-------. 1 root root 125811 Nov 23 2013 moduli
    -rw-r--r--. 1 root root 2047 Nov 23 2013 ssh_config
    -rw------- 1 root root 3639 May 16 11:43 sshd_config
    -rw------- 1 root root 668 May 20 23:31 ssh_host_dsa_key
    -rw-r--r-- 1 root root 590 May 20 23:31 ssh_host_dsa_key.pub
    -rw------- 1 root root 963 May 20 23:31 ssh_host_key
    -rw-r--r-- 1 root root 627 May 20 23:31 ssh_host_key.pub
    -rw------- 1 root root 1675 May 20 23:31 ssh_host_rsa_key
    -rw-r--r-- 1 root root 382 May 20 23:31 ssh_host_rsa_key.pub

检查文件有效性

  1. 如果参阅前述步骤,修改相关文件权限后,还是无法正常连接。由于SSH服务在启动时会自动重建丢失的密钥文件。依次执行以下命令,确认存在ssh_host_*文件。
    cd /etc/ssh/
    ll
    系统显示类似如下。
    total 156
    -rw-------. 1 root root 125811 Nov 23  2013 moduli
    -rw-r--r--. 1 root root   2047 Nov 23  2013 ssh_config
    -rw-------  1 root root   3639 May 16 11:43 sshd_config
    -rw-------  1 root root    672 May 20 23:08 ssh_host_dsa_key
    -rw-r--r--  1 root root    590 May 20 23:08 ssh_host_dsa_key.pub
    -rw-------  1 root root    963 May 20 23:08 ssh_host_key
    -rw-r--r--  1 root root    627 May 20 23:08 ssh_host_key.pub
    -rw-------  1 root root   1675 May 20 23:08 ssh_host_rsa_key
    -rw-r--r--  1 root root    382 May 20 23:08 ssh_host_rsa_key.pub
  2. 执行以下命令,删除相关文件。
    rm -rf ssh_host_*
    说明:对于Ubuntu、Debain类的操作系统,删除相关文件的命令以下所示。
    sudo rm -r /etc/ssh/ssh*key
  3. 执行ll命令,确认文件删除成功。
    total 132
    -rw-------. 1 root root 125811 Nov 23  2013 moduli
    -rw-r--r--. 1 root root   2047 Nov 23  2013 ssh_config
    -rw-------  1 root root   3639 May 16 11:43 sshd_config
  4. 执行以下命令,重启SSH服务,自动生成相关文件。
    service sshd restart
    说明:对于Ubuntu、Debain类的操作系统,重启SSH服务的命令以下所示。
    sudo dpkg-reconfigure openssh-server
  5. 执行ll命令,确认成功生成ssh_host_*文件。
    total 156
    -rw-------. 1 root root 125811 Nov 23  2013 moduli
    -rw-r--r--. 1 root root   2047 Nov 23  2013 ssh_config
    -rw-------  1 root root   3639 May 16 11:43 sshd_config
    -rw-------  1 root root    668 May 20 23:16 ssh_host_dsa_key
    -rw-r--r--  1 root root    590 May 20 23:16 ssh_host_dsa_key.pub
    -rw-------  1 root root    963 May 20 23:16 ssh_host_key
    -rw-r--r--  1 root root    627 May 20 23:16 ssh_host_key.pub
    -rw-------  1 root root   1671 May 20 23:16 ssh_host_rsa_key
    -rw-r--r--  1 root root    382 May 20 23:16 ssh_host_rsa_key.pub
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

a1809032425

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值