• 解决ssh无密码登录不成功的问题


    把ssh设置为无密码登录很简单,只需两步:

    1、在本地创建公钥和私钥:

    ssh-keygen -t rsa

    2、然后把公钥上传到远程机器上:

    ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.41.132

    正常情况下经这两步设置就可无密码登录了:

    ssh 192.168.41.132

    可是今碰到的问题是仍要输入密码,网上找了找资料,有说要 restorecon ,也有说要 chmod ,最终在 /var/log/audit/audit.log 中发现了问题:

    # cat /var/log/audit/audit.log
    ...
    type=AVC msg=audit(1417198093.916:14807): avc:  denied  { search } for  pid=1977 comm="sshd" name="/" dev=vdb1 ino=2 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:file_t:s0 tclass=dir
    ...

    这里报了 avc:  denied  { search } 的错误,属于SELinux安全性问题,解决该问题的方法是:

    1、把 /var/log/audit/audit.log 文件中报错的行拷贝到临时文件 /tmp/error.txt :

    # grep "avc:  denied  { search }" /var/log/audit/audit.log > /tmp/error.txt

    2、执行下面的命令让系统自己找原因:

    # audit2why -i /tmp/error.txt
    type=AVC msg=audit(1417198093.916:14807): avc: denied { search } for pid=1977 comm="sshd" name="/" dev=vdb1 ino=2 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:file_t:s0 tclass=dir
    
      Was caused by:
        Missing type enforcement (TE) allow rule.
    
    You can use audit2allow to generate a loadable module to allow this access.

    3、按上面命令的输出说明,执行:

    # audit2allow -i /tmp/error.txt -M local
    ******************** IMPORTANT ***********************
    To make this policy package active, execute:
    
    semodule -i local.pp

    4、按上面命令的输出说明,执行:

    semodule -i local.pp

    这样就解决了 avc:  denied  { search } 问题。

    解决掉这个问题后,再执行ssh登录仍然需要输入密码。为此又查看了 /var/log/audit/audit.log 文件尾部,新发现了 avc:  denied  { getattr } 报错,解决方法同上面的1-4步。解决掉这两个报错后就可无密码登录了。

  • 相关阅读:
    UICollectionViewController用法
    UISegmentedControl的详细使用
    &#x开头的是什么编码呢。浏览器可以解释它。如中国等同与中文"中国"?
    Random.nextint() 和Math.random()的区别
    UIGestureRecognizer ios手势识别温习
    [工具]Mac平台开发几个网络抓包工具(sniffer)
    IOS中Json解析的四种方法
    iOS官方Sample大全
    Ubuntu 16.04安装cuda7.5 GCC
    Ubuntu中升极下载4.2内核
  • 原文地址:https://www.cnblogs.com/yang-wu/p/4131149.html
Copyright © 2020-2023  润新知