ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)

【ansible 设置host为localhost,执行ping命令报错】
[eniq-s@localhost ansible]$ ansible all -m ping -i inventory 
localhost | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", 
    "unreachable": true
}

https://serverfault.com/questions/1085427/ansible-playbook-not-running-for-localhost-also-how-to-fix-this

【加 -k 交互式输入密码可以成功】
[eniq-s@localhost ansible]$ ansible all -k -m ping -i inventory 
SSH password: 
localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

https://wenku.baidu.com/view/4a4a69f64a649b6648d7c1c708a1284ac85005a7.html?_wkts_=1677651890658&bdQuery=authorized_keys%E6%96%87%E4%BB%B6%E5%9C%A8%E5%93%AA

【在local生成公钥,导入到server上的~/.ssh/authorized_keys, 之后问题解决】

[eniq-s@localhost ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/eniq-s/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/eniq-s/.ssh/id_rsa.
Your public key has been saved in /home/eniq-s/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:E3Hamok7mfc4bxwEdLSfCxqnmau9rMKqzUryhDyrMHM eniq-s@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|       .o.+      |
|        .* .     |
|        o.o      |
|       . =.. .   |
|      . S.o o    |
|..     + O.. .   |
|*+E.  = *. ..    |
|+Oo o  =.+o      |
|=+=. .oo*=o      |
+----[SHA256]-----+
[eniq-s@localhost ~]$ ls -alt .ssh/
total 12
drwx------.  2 eniq-s eniq-s   57 Feb 28 23:38 .
-rw-------.  1 eniq-s eniq-s 1679 Feb 28 23:38 id_rsa
-rw-r--r--.  1 eniq-s eniq-s  410 Feb 28 23:38 id_rsa.pub
drwx------. 10 eniq-s eniq-s  252 Feb 28 22:44 ..
-rw-r--r--.  1 eniq-s eniq-s  171 Feb 28 20:36 known_hosts
[eniq-s@localhost ~]$ 
[eniq-s@localhost ~]$ pwd
/home/eniq-s
[eniq-s@localhost ~]$ cat >> .ssh/authorized_keys  < .ssh/id_rsa.pub 

[eniq-s@localhost ~]$ ansible all  -m ping -i ./ansible/inventory   
localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值