1、SSH登录
#shell
ssh 用户名@IP
# or
ssh 用户名@IP -p22
#eg. ssh sshuser@192.168.1.1 -p22
2、常见问题
ssh登录一些老旧设备,可能会出现以下问题:
问题1
Unable to negotiate with 192.168.xx.xx port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
解决1
添加秘钥交换算法支持
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 用户名@IP
ssh -oKexAlgorithms=+diffie-hellman-group-exchange-sha1 用户名@IP
问题2
Unable to negotiate with 192.168.xx.xx port 22: no matching host key type found. Their offer: ssh-dss,ssh-rsa
解决2
因为OpenSSH 7.0以后的版本不再支持ssh-dss (DSA)算法,8.8版本后不再支持ssh-rsa 算法,所以添加上。
#缺什么加什么
ssh -oHostKeyAlgorithms=+ssh-dss 用户名@IP
ssh -oHostKeyAlgorithms=+ssh-rsa 用户名@IP
问题3
Unable to negotiate with 192.168.xx.xx port 22: no matching cipher found. Their offer: aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,3des-cbc,des-cbc
解决3
添加密码加密方法支持
#选其一
ssh -oCiphers=+3des-cbc 用户名@IP
ssh -v aes128-cbc 用户名@IP
问题4
ssh_dispatch_run_fatal: Connection to 192.168.xx.xx port 22: Invalid key length
解决4
SSH登录需要使用RSA密钥或者是DSA密钥,OpenSSH版本升级到了7.6之后,小于1024bits的RSA keys已经不被支持了。目前主流密钥长度至少都是1024bits以上,低于1024bit的密钥在windows 10 系统和较新发行版本的linux版本中认为不安全,所以在使用密钥长度低于1024bits时就会出现密钥长度的错误信息。
需要对设备进行配置。输入以下命令随后确认并设置密匙长度为2048。
[Huawei]rsa local-key-pair create
[Huawei]rsa local-key-pair create
The key name will be: Huawei_Host
% RSA keys defined for Huawei_Host already exist.
Confirm to replace them? [y/n]:y
The range of public key size is (512 ~ 2048).
NOTES: If the key modulus is greater than 512,
it will take a few minutes.
Input the bits in the modulus[default = 512]:2048
Generating keys...
......+++
................................................................................
..................................+++
......++++++++
..........++++++++
[Huawei]qiit
<Huawei>save
问题5
shell request failed on channel 0
解决5
交换机ssh用户没有添加服务类型
[Huawei]ssh user 用户名 service-type all
or
[Huawei]ssh user 用户名 service-type ssh
3、配置文件修改
如果上述问题都出现了,最后命令可能是这样的:
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-dss -oCiphers=+3des-cbc user@192.168.xx.xx
当然, 每次连接敲这么一长串也不太好.
编辑用户 ssh 配置 ~/.ssh/config,Windows下是路径是 C:\User\用户名\.ssh\config,没有这个文件就原地创建一个config,无文件扩展名,增加配置项:
Host 主机名字 #ip映射下的主机名
Hostname IP #ssh连接的ip地址
User 用户名字 #登录用户名
Port 22 #端口
PreferredAuthentications publickey #免密登录
IdentityFile ~/.ssh/id_rsa #密钥位置
#上述解决问题时的配置
#HostKeyAlgorithms +ssh-dss
HostKeyAlgorithms +ssh-rsa
KexAlgorithms +diffie-hellman-group1-sha1
#KexAlgorithms +diffie-hellman-group-exchange-sha1
Ciphers +3des-cbc
#Ciphers +aes128-cbc
参考文章
[1] ssh 登录旧设备的问题解决
[2] SSH登录失败常见问题
[3] 交换机SSH常见问题解决办法
[4] 锐捷网络设备 SSH 登录报 Invalid key length 错
[5] Solution to openssh-8.8-p1 update: no matching host key type found. Their offer: ssh-rsa