一、Debian开启SSH

参考链接:

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
  1. 执行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
  1. 系统显示类似如下。
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
  1. 执行以下命令,删除相关文件。
rm -rf ssh_host_*

说明:对于Ubuntu、Debain类的操作系统,删除相关文件的命令以下所示。
sudo rm -r /etc/ssh/ssh*key

  1. 执行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
  1. 执行以下命令,重启SSH服务,自动生成相关文件。
service sshd restart

说明:对于Ubuntu、Debain类的操作系统,重启SSH服务的命令以下所示。
sudo dpkg-reconfigure openssh-server

  1. 执行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