---
title: "linux  ssh无法实现免密码登录"
author: "flyeagle"
date: "2015-03-14T15:34:08Z"
tags: []
categories: ["操作系统"]
slug: "linux-ssh"
draft: false
lastmod: "2015-03-14T15:35:09Z"
id: 2192303
url: "https://flyeagle.iteye.com/blog/2192303"
---

根据之前的设置或网上的很多介绍，始终无法做到免密码登录，经过多次测试，最终解决:

使用root:

vi /etc/ssh/sshd\_config 

Protocol 2 

PasswordAuthentication no 

PubkeyAuthentication yes 

#AuthorizedKeysFile      .ssh/authorized\_keys

 

service sshd restart

 

使用要免密码登录的用户执行:

ssh-keygen -t dsa -P '' -f ~/.ssh/id\_dsa

cat ~/.ssh/id\_dsa.pub &gt;&gt; ~/.ssh/authorized\_keys

 

 

chmod 644 authorized\_keys

chmod 700 -R .ssh  //设置免密码登录用户主目录下的隐藏目录.ssh

 

ssh localhost

报:

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

这个问题是因为SELinux被打开了，暂时关闭(重启恢复):

 

setenforce 0  //使用root执行

 

vi /etc/selinux/config 

  SELINUX=disabled