关于git的ssh permission denied原因汇总

时间:2023-03-09 03:31:01
关于git的ssh permission denied原因汇总

SSH关于公钥认证Permission denied (publickey,gssapi-with-mic的问题

http://h2appy.blog.51cto.com/609721/1112797

CentOS 6.3系统下,用户user的home目录:/home/user的权限变成了777,造成不能正常登陆SSH,报如下错误:Permission denied (publickey,gssapi-with-mic

SSH对公钥、私钥的权限和所有权的要求是非常严格的,总结如下:

1、下面两个目录的所有权必须是user,所属组也应该是user,权限必须为700

\home\user

\home\user\.ssh

2、下面公钥文件的所有权必须是user,所属组也应该是user,权限必须为644

\home\user\.ssh\authorized_keys

3、下面私钥文件的所有权必须是user,所属组也应该是user,权限必须是600

\home\user\.ssh\id_rsa

ssh使用公钥授权不通过的问题解决

http://www.2cto.com/os/201206/137286.html

ssh使用公钥授权不通过的问题解决
前提: 
1.客户端生成了id_rsa.pub和id_rsa 
2.服务端在.ssh/authorized_keys也加入了客户端的id_res.pub 
3./etc/ssh/sshd_config开启了: 
Shell代码    www.2cto.com  
RSAAuthentication yes  
PubkeyAuthentication yes  
AuthorizedKeysFile     .ssh/authorized_keys  
但在客户端执行ssh依然报错: 
Shell代码  
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).  
在这个页面不小心看到了原因: 
 
http://serverfault.com/questions/230771/ssh-configuration-publickeys-permission-denied-publickey-password-error 
又是TM的SELinux惹的祸,关闭SELinux解决问题: 
暂时关闭(重启后恢复): 
Shell代码    www.2cto.com  
setenforce 0  
永久关闭(需要重启): 
Shell代码  
vi /etc/selinux/config  
SELINUX=disabled  
另: 
ssh可同时支持publickey和password两种授权方式,publickey默认不开启,需要配置为yes。 
如果客户端不存在.ssh/id_rsa,则使用password授权;存在则使用publickey授权;如果publickey授权失败,依然会继续使用password授权。

OpenSSH 无密码访问配置

http://www.linuxidc.com/Linux/2012-06/62932.htm

Ubuntu下OpenSSH的安装:

sudo apt-get install openssh-server

一、问题描述

假设 A 为客户机器,B为目标机;

要达到的目的:

A机器ssh登录B机器无需输入密码;

加密方式选 rsa|dsa均可以,默认dsa

二、具体操作流程

单向登陆的操作过程(能满足上边的目的):

1、登录A机器

2、ssh-keygen -t [rsa|dsa],将会生成密钥文件和私钥文件 id_rsa,id_rsa.pub或id_dsa,id_dsa.pub

3、将 .pub 文件复制到B机器的 .ssh 目录, 并 cat id_dsa.pub > ~/.ssh/authorized_keys

4、大功告成,从A机器登录B机器的目标账户,不再需要密码了;(直接运行 #ssh 192.168.20.60 )

双向登陆的操作过程:

1、ssh-keygen做密码验证可以使在向对方机器上ssh ,scp不用使用密码.具体方法如下:

2、两个节点都执行操作:#ssh-keygen -t rsa

然后全部回车,采用默认值.

3、这样生成了一对密钥,存放在用户目录的~/.ssh下。

将公钥考到对方机器的用户目录下 ,并将其复制到~/.ssh/authorized_keys中(操作命令:#cat id_dsa.pub >> ~/.ssh/authorized_keys )。

4、设置文件和目录权限:

设置authorized_keys权限

$ chmod 600 authorized_keys

设置.ssh目录权限

$ chmod 700 -R .ssh

5、要保证.ssh和authorized_keys都只有用户自己有写权限。否则验证无效。(今天就是遇到这个问题,找了好久问题所在),其实仔细想想,这样做是为了不会出现系统漏洞。

我从20.60去访问20.59的时候会提示如下错误:

The authenticity of host '192.168.20.59 (192.168.20.59)' can't be established.  RSA key fingerprint is 6a:37:c0:e1:09:a4:29:8d:68:d0:ca:21:20:94:be:18.  Are you sure you want to continue connecting (yes/no)? yes  Warning: Permanently added '192.168.20.59' (RSA) to the list of known hosts.  root@192.168.20.59's password:   Permission denied, please try again.  root@192.168.20.59's password:   Permission denied, please try again.  root@192.168.20.59's password:   Permission denied (publickey,gssapi-with-mic,password).

三、总结

1、文件和目录的权限千万别设置成chmod 777.这个权限太大了,不安全,数字签名也不支持。

2、生成的rsa/dsa签名的公钥是给对方机器使用的,这个公钥内容还要拷贝到authorized_keys

3、linux之间的访问直接 ssh 机器ip4、某个机器生成自己的RSA或者DSA的数字签名,将公钥给目标机器,然后目标机器接收后设定相关权限(公钥和authorized_keys权限),这个目标机就能被访问了!

SSH : Permission denied(publickey,gssapi-with-mic)

http://blog.csdn.net/ashlingr/article/details/7670338

在搭载Hadoop集群过程中,涉及到 配置SSH使用无密码公钥认证,遇到了SSH : Permission denied (publickey,gssapi-with-mic)错误。现将解决方式记录下:(由于解决问题的时间和过程过长,有可能会缺少了其中一些步骤,仅供参考)
      最终找到的错误原因:为了保证sshd_config的配置一致性,在普通用户下,登录root,从另外一台机子上将/etc/ssh文件夹中的sshd_config拷贝到这台机子上。但是这样的操作会改变sshd_config的权限,在ls命令下看到文件变为绿色,与其他配置文件不同,再用“ls -al”查看,sshd_config权限为“-rw-r--r--  ”,将其改为“-rw------- ”,即可。命令:chmod 600 sshd_config。
      另外:authorized_keys 的权限为“-rw-------”,即600。
      最后,sshd_config配置文件如下:
 
#    $OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
#Protocol 2,1
Protocol 2
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

#RSAAuthentication yes
#PubkeyAuthentication yes
#PubkeyAuthentication no
#AuthorizedKeysFile    .ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
#PasswordAuthentication yes
PasswordAuthentication no
AuthorizedKeysFile .ssh/authorized_keys

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication mechanism. 
# Depending on your PAM configuration, this may bypass the setting of 
# PasswordAuthentication, PermitEmptyPasswords, and 
# "PermitRootLogin without-password". If you just want the PAM account and 
# session checks to run without PAM authentication, then enable this but set 
# ChallengeResponseAuthentication=no
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES 
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT 
AcceptEnv LC_IDENTIFICATION LC_ALL
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner /some/path

# override default of no subsystems
Subsystem    sftp    /usr/libexec/openssh/sftp-server

SSH 登录是错误:Permission denied (publickey,gssapi-with-mic)

http://www.oschina.net/question/54100_28922

$ ssh root@192.168.xx.xx

Permission denied (publickey,gssapi-with-mic).

报了这么个错,原因是我上次做测试时修改了/etc/ssh/sshd_config 中的"PasswordAuthentication"参数值为"no",修改回"yes",重启sshd服务即可。

git@osc 上传公钥总是失败的问题

http://my.oschina.net/230/blog/145883

复制公钥到http://git.oschina.net/keys里时提示:

  • Key can't be fingerprinted

或者提示:

  • Key 是无效的

这都是文本格式问题,因为我都是在终端使用命令:

cat ~/.ssh/id_rsa.pub

获取然后复制过去的,即使去掉了复制过程中而外的空格,还是提示上诉错误。

另外在文本编辑器中打开,然后c-a,c-c,复制过去就可以了,,

:-)

笔记~SSH无需密码密钥登录,centos 5.5 下成功

http://my.oschina.net/emptytimespace/blog/79173

笔记~SSH无需密码密钥登录,centos 5.5 下成功
(太多太久,已经忘记引用哪里的了,如有侵权,请留言)
------***
3.SSH 无密码登录设置
3.1 在node00节点上运行
ssh-keygen -t rsa
然后一路确定,3个,
执行
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
cd ~/.ssh 
cat authorized_keys
然后每个节点都运行上面的命令,将cat authorized_keys 中的结果全部拷贝到 node00 的authorized_keys 中,
在 node00上 修改权限
chmod 644 ~/.ssh/authorized_keys 
然后将该文件拷贝到node00 /home 下
cp ~/.ssh/authorized_keys /home
(我的是 cp ~/.ssh/authorized_keys /mnt/myshare/ )
到各个节点运行
cp /home/authorized_keys ~/.ssh/authorized_keys
(我的是 cp /mnt/myshare/authorized_keys ~/.ssh/authorized_keys)
这个时候可以ssh无密码登录各个节点,比如 ssh node00
第一次的时候需要yes确认一下,以后不需要了。
------***
1  修改ssh配置文件(master和slave1都要修改)
#vi /etc/ssh/sshd_config
   具体设置:
a、打开AuthorizedKeysFile,就是删除前面的#号(如果有的话)
b、添加允许访问的帐户,AllowUsers hadoop。
2、通过ssh-keygen产生RSA公私密钥对(密码为空)(master和slave1都要运行)
hadoop$ssh-keygen -t rsa -P ""
这样会在/home/hadoop/.ssh/下生成id_rsa和id_rsa.pub
3  将各个联机中的~/.ssh/authorized_keys 中的密钥收集起来,集合为一个,再分发到每个联机。
4、重启ssh服务
ubuntu#/etc/init.d/sshd -reload
这样master和slave1就可以互访而不用输入密码。
------***
**:注意,如果两边操作都没有问题,那么请注意要修改authorized_keys中用户名后的地址为
         localhost.localdomain:
例如root@h1.test.com.cn  -->  root@localhost.localdomain
我的nsplab-calc.ustc.edu.cn 修改为 nsplab-calc.local
------
配置 ssh 实现 MPI 节点间用户的无密码访问,由于 MPI 并行程序需要在各节点间进行信息传递,所以必须实现所有节点两两之间能无密码访问。
节点间的无密码访问是通过配置ssh 公钥认证来实现的。例如,对新用户 user 配置 ssh 公钥认证,先在 c1 上做以下操作。
(1)生成了私钥 id_dsa 和公钥 id_dsa.pub,具体操作方法如下。
ssh-keygen -t rsa
   系统显示一些信息,遇到系统询问直接回车即可。
(2)将该密钥用作认证,进行访问授权。按如下命令在 c1 执行。
cp ~/.ssh/id_dsa.pub ~/.ssh/authorized_keys
   由于我们使用的是 root 用户,所以~代表/root,
(3)将~/.ssh 目录下的文件复制到所有节点。
scp -r ~/.ssh/* c2:/root/.ssh
(4)检查是否可以直接(不需要密码)登录其他节点。
ssh c2
   如能两两之间不需要密码登录其他节点,则表明配置成功。

SSH公钥无密码认证

http://my.oschina.net/heartdong/blog/135374

1)在master主机上生成密码对

1 ssh-keygen –t rsa –P ''

确认一路回车,命令默认会在用户主目录下生成.ssh目录,你们有两 密钥对文件:id_rsa和id_rsa.pub

1 [master@hadoop ~]$ ll .ssh/
2 -rw-------. 1 master master 1675 Jun  3 00:28 id_rsa
3 -rw-r--r--. 1 master master  402 Jun  3 00:28 id_rsa.pub

接着在master节点上做如下配置,把id_rsa.pub追加到授权的key里面去。

1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

本以为这么就可以搞定了的,发现输入命令ssh localhost还是要密码。

捣鼓了半天,终于还是被我找到了原因

找到服务器修改SSH配置文件"/etc/ssh/sshd_config",修改如下内容(去掉前面的注释)

1 RSAAuthentication yes # 启用 RSA 认证
2 PubkeyAuthentication yes # 启用公钥私钥配对认证方式
3 AuthorizedKeysFile .ssh/authorized_keys # 公钥文件路径(和上面生成的文件同)

设置完之后记得 重启SSH服务

1 service sshd restart

重新验证ssh localhost,无密码登陆成功

配置远程登陆其他机器也是同一个原理,只需把本机生成的id_rsa.pub上传到其他服务器做同样操作即可。

ssh: permission denied (publickey)

http://www.blogjava.net/dongbule/archive/2011/01/04/342275.html

ssh出现permission denied (publickey)问题:
修改/etc/ssh/sshd-config文件.
将其中的PermitRootLogin no修改为yes
PubkeyAuthentication yes修改为no
AuthorizedKeysFile .ssh/authorized_keys前面加上#屏蔽掉,
PasswordAuthentication no修改为yes就可以了。

vi /etc/ssh/sshd-config (详细说说sshd-config的配置解释)
Subsystem       sftp    /usr/libexec/openssh/sftp-server
Port 22
Protocol 2
PermitRootLogin no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#CACertificateFile  /etc/ssh/ca/ca.cert
PasswordAuthentication no
PermitEmptyPasswords no
PrintMotd no
ChallengeResponseAuthentication no
UseDNS no
ClientAliveInterval 60

Port 22 # SSH 预设使用 22 这个 port,您也可以使用多的 port !亦即重复使用 port 这个设定项目即可!

Protocol 2 # 选择的 SSH 协议版本,可以是 1 也可以是 2 ,如果要同时支持两者,就必须要使用 2,1 这个分隔了

PermitRootLogin no
# 是否允许 root 登入!预设是允许的,但是建议设定成 no! PubkeyAuthentication yes # 是否允许 Public Key AuthorizedKeysFile .ssh/authorized_keys # 上面这个在设定若要使用不需要密码登入的账号时,那么那个账号的存放档案所在档名! PasswordAuthentication no # 是否需要密码的验证 PermitEmptyPasswords no # 若上面那一项如果设定为 yes 的话,这一项就最好设定为 no ,这个项目在是否允许以空的密码登入!当然不许! PrintMotd no # 登入后是否显示出一些信息呢?例如上次登入的时间、地点等 ChallengeResponseAuthentication no # 是否启用其它的 PAM 模块!启用这个模块将会导致 PasswordAuthentication 设定失效! UseDNS no ClientAliveInterval 60

ssh使用公钥授权不通过的问题解决

http://www.2cto.com/os/201206/137286.html

ssh使用公钥授权不通过的问题解决
前提: 
1.客户端生成了id_rsa.pub和id_rsa 
2.服务端在.ssh/authorized_keys也加入了客户端的id_res.pub 
3./etc/ssh/sshd_config开启了: 
Shell代码    www.2cto.com  
RSAAuthentication yes  
PubkeyAuthentication yes  
AuthorizedKeysFile     .ssh/authorized_keys  
但在客户端执行ssh依然报错: 
Shell代码  
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).  
在这个页面不小心看到了原因: 
 
http://serverfault.com/questions/230771/ssh-configuration-publickeys-permission-denied-publickey-password-error 
又是TM的SELinux惹的祸,关闭SELinux解决问题: 
暂时关闭(重启后恢复): 
Shell代码    www.2cto.com  
setenforce 0  
永久关闭(需要重启): 
Shell代码  
vi /etc/selinux/config  
SELINUX=disabled  
另: 
ssh可同时支持publickey和password两种授权方式,publickey默认不开启,需要配置为yes。 
如果客户端不存在.ssh/id_rsa,则使用password授权;存在则使用publickey授权;如果publickey授权失败,依然会继续使用password授权。