關於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的SE Linux惹的禍,關閉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的SE Linux惹的禍,關閉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授權。
 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM