首页 技术 正文
技术 2022年11月6日
0 收藏 539 点赞 931 浏览 1684 个字

通常情况下,我会使用非对称加密的方式来进行ssh的登录。

做法:

  将公钥添加到 $HOME/.ssh/authorized_keys 文件中。

但是通常,会遇见各种各样的问题,导致失败。汇总如下:

0. 常用的排除手段,一般就是,双端开debug,clinet开启的方式如下,server还从来没与与遇见过需要开的情况,一般开client端就都搞定了。

/home/tong [tong@T7] [:]
> ssh -vvvvv root@t54
OpenSSH_7.5p1, OpenSSL 1.1.0e Feb
debug1: Reading configuration data /home/tong/.ssh/config
debug1: /home/tong/.ssh/config line : Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config

1. 使用的私钥加密算法已经被openssh弃用,如 之前的 ssh-dss 就已经被新版openssh启用了,如果启用,可以如下配置:

/home/tong [tong@T7] [:]
> cat ~/.ssh/config
HOST *
HostKeyAlgorithms +ssh-dss
ForwardX11 yes

  还可以通过命令和man手册,查看都支持那些算法。详细操作略。

2.  万恶的selinux搞得鬼, 禁掉禁掉,stopstop。

  具体操作略。

  然鹅,使用selinux一定有其好处以及必要性,所以还是需要花些时间,学习一下。

  无意中看到的一个参考:

    The SELinux contexts need to be right as well if you didn’t disable that. The command “restorecon -R .ssh” should fix that.

3.  authorized_keys 文件的权限不对,改成644, 记不太清了,记忆的深处好像是有这么回事的。。。

4.  同样的key,root用户好用,tong用户便不好用。debug之后,发现server返回的是:

debug3: receive packet: type 

  google之

  https://superuser.com/questions/1137438/ssh-key-authentication-fails

  当前的权限是:

[root@T54 ~]# ll -a  /home/tong/  |grep '\.ssh'
drwxrwxr-x. tong tong May : .ssh
[root@T54 ~]# ll -a /root/ |grep '\.ssh'
drwxr-xr-x root root May : .ssh
[root@T54 ~]#

  改过权限之后,好用了:

[tong@T54 ~]$ ll -a |grep '\.ssh'
drwxr-xr-x. tong tong May : .ssh
[tong@T54 ~]$ ll .ssh/
total
-rw-r--r-- tong tong May : authorized_keys
[tong@T54 ~]$

——————————-  update @ 2017-10-24 —————————-

排除以上情況依然会有key不好使的时候. 这次有被我遇到.

以往, 一直在ssh的时候使用-vvvv 来排除故障, 然而这种方法其实是愚蠢的. 因为, 这会给黑客们可称之机.

查看server的 /var/log/secure 日志文件, 将发现更多的错误信息, 如下:

> sudo tail -f /var/log/secure
Sep :: new-server sshd[]: Authentication refused: bad ownership or modes for directory /home/dave/.ssh

我这次遇到错误是:

 Authentication refused: bad ownership or modes for directory /root

因为root目录的owner被改成了game组…..

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905