當前位置:首頁 » 操作系統 » 免密碼sshlinux

免密碼sshlinux

發布時間: 2022-10-04 21:28:48

linux下怎樣設置ssh無密碼登錄

首先你要有一個無密碼的用戶。
修改ssh配置文件,步驟如下:
1)
修改 /etc/ssh/sshd_config
文件中 PermitEmptyPasswords
這個參數為yes(即允許空密碼的用戶登錄,默認是no)
2)
重啟
ssh服務,service
ssh
restart
3)
重新登錄ssh,即可無密碼登錄。

② linux下怎樣設置ssh無密碼登錄

ssh-keygen 生成密鑰
公鑰拷貝到對方機器,其實應該是追加,別沖了原文件。
scp ~/.ssh/id_rsa.pub 192.168.xxx.xxx:~/.ssh/authorized_keys
有了別人的公鑰,就可以登錄了。第一次要指紋確定一次。

③ linux下怎樣設置ssh無密碼登錄

1) 在本地主機生成密鑰對
ssh-keygen -t rsa
這個命令生成一個密鑰對:id_rsa(私鑰文件)和id_rsa.pub(公鑰文件)。默認被保存在~/.ssh/目錄下。
2) 將公鑰添加到遠程主機的 authorized_keys 文件中
將文件上傳到遠程主機中
scp ~/.ssh/id_rsa.pub [email protected]:/root/
SSH到登陸到遠程主機192.168.17.113,將公鑰追加到 authorized_keys 文件中
cat /root/id_rsa.pub >> /root/.ssh/authorized_keys
或直接運行命令:
cat ~/.ssh/id_dsa.pub|ssh [email protected] 'sh -c "cat - >>~/.ssh/authorized_keys"'
3) 重啟 open-ssh 服務
/etc/init.d/ssh restart
4) 本地測試
ssh [email protected]

④ linux下怎樣設置ssh無密碼登錄

用SSL加密Key實現自動登錄
需要材料:
1 被管理的SSH伺服器一台。
2 管理端電腦一台。

環境:
管理伺服器: ip:192.168.0.1 機器名:server
被管理伺服器:ip:192.168.0.2 機器名:client

生成密鑰對:
生成公鑰密鑰對是在管理伺服器上生成的:

[root@server ~]# ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair. #提示正在生成rsa密鑰對
Enter file in which to save the key (/home/usrname/.ssh/id_dsa): #詢問公鑰和私鑰存放的位置,回車用默認位置即可
Enter passphrase (empty for no passphrase): #詢問輸入私鑰密語,輸入密語
Enter same passphrase again: #再次提示輸入密語確認
Your identification has been saved in /home/usrname/.ssh/id_dsa. #提示公鑰和私鑰已經存放在/root/.ssh/目錄下
Your public key has been saved in /home/usrname/.ssh/id_dsa.pub.
The key fingerprint is:
x6:68:xx:93:98:8x:87:95:7x:2x:4x:x9:81:xx:56:94 root@server #提示key的指紋

拷貝你的公鑰到被管理的伺服器上
在你的管理伺服器上把你的公鑰拷貝到被管理伺服器上要進行自動登陸的用戶目錄下。

[root@server ~]# scp .ssh/id_dsa.pub [email protected]: #比如你想使用用戶peter登陸,則remote_usrname請以peter代替

改名和進行許可權設置
登陸被管理的伺服器,進入需要遠程登陸的用戶目錄,把公鑰放到用戶目錄的 .ssh 這個目錄下(如果目錄不存在,需要創建~/.ssh目錄,並把目錄許可權設置為700),把公鑰改名為authorized_keys2,並且把它的用戶許可權設成600。

[peter@client ~]$ ls
id_rsa.pub
[peter@client ~]$ mkdir ~/.ssh #如果當前用戶目錄下沒有 .ssh 目錄,請先創建目錄
[peter@client ~]$ chmod 700 ~/.ssh
[peter@client ~]$ mv id_rsa.pub ~/.ssh
[peter@client ~]$ cd ~/.ssh
[peter@client ~]$ cat id_rsa.pub >> authorized_keys2
[peter@client ~]$ rm -f id_rsa.pub
[peter@client ~]$ chmod 600 authorized_keys2
[peter@client ~]$ ls -l
total 4
-rw------- 1 peter peter 225 Oct 10 11:28 authorized_keys2

測試使用密鑰對進行遠程登陸

[root@server ~]# ssh [email protected]
Enter passphrase for key '/root/.ssh/id_rsa': #提示輸入密碼短語,請輸入剛才設置的密碼短語
Last login: Sun Oct 10 11:32:14 2010 from 192.168.0.1
[peter@client ~]$

如果你不能用正確的登錄,應該重新檢查一下你的authorized_keys2的許可權。也可能要檢查.ssh目錄的許可權。
使用 ssh-agent(ssh代理)自動輸入密碼短語
牢記你的「密碼短句」,現在你可以用你的密鑰而不是密碼來登錄你的伺服器了,但是這樣仍然沒有省什麼事,你還是要輸入密鑰的「密碼短語」。有更簡便的方法嗎?答案就是採用SSH代理(ssh-agent),一個用來幫你記住「密碼短語」的程序。 ssh-agent是OpenSSH中默認包括的ssh代理程序。
登陸管理伺服器

[root@server ~]# ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147; export SSH_AUTH_SOCK;
SSH_AGENT_PID=2148; export SSH_AGENT_PID;
echo Agent pid 2148;

當你運行ssh-agent,它會列印出來它使用的 ssh 的環境和變數。要使用這些變數,有兩種方法,一種是手動進行聲明環境變數,另一種是運行eval命令自動聲明環境變數。
方法一:手動聲明環境變數

[root@server ~]# SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147; export SSH_AUTH_SOCK;
[root@server ~]# SSH_AGENT_PID=2148; export SSH_AGENT_PID;
[root@server ~]# printenv | grep SSH #檢查 ssh 環境變數是否已經加入當前會話的環境變數
SSH_AGENT_PID=2148
SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147

方法二:運行eval命令自動聲明環境變數

[root@server ~]# eval `ssh-agent`
Agent pid 2157
[root@server ~]# printenv | grep SSH #檢查 ssh 環境變數是否已經加入當前會話的環境變數
SSH_AGENT_PID=2148
SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147

現在 ssh-agent 已經在運行了,但是 ssh-agent 裡面是空白的不會有解密的專用密鑰。我們要告訴它我們有私鑰和這個私鑰在哪兒。這就需要使用 ssh-add 命令把我們的專用密鑰添加到 ssh-agent 的高速緩存中。

[root@server ~]# ssh-add ~/.ssh/id_dsa
Enter passphrase for /home/user/.ssh/id_dsa: #輸入你的密碼短語
Identity added: /home/user/.ssh/id_dsa (/home/user/.ssh/id_dsa)
[root@server ~]# ssh-add -l #查看 ssh代理的緩存內容
1024 72:78:5e:6b:16:fd:f2:8c:81:b1:18:e6:9f:77:6e:be /root/.ssh/id_rsa (RSA)

輸入了密碼短句,現在好了,你可以登錄你的遠程伺服器而不用輸入你的密碼短語了,而且你的私鑰是密碼保護的。

⑤ linux下怎樣設置ssh無密碼登錄

第1步:在本地主機中生成「密鑰對」並將公鑰傳送到遠程伺服器中:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):直接敲擊回車或設置密鑰的存儲路徑
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 直接敲擊回車或設置密鑰的密碼
Enter same passphrase again: 再次敲擊回車或設置密鑰的密碼
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
40:32:48:18:e4:ac:c0:c3:c1:ba:7c:6c:3a:a8:b5:22 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|+*..o . |
|*.o + |
|o* . |
|+ . . |
|o.. S |
|.. + |
|. = |
|E+ . |
|+.o |
+-----------------+

第2步:將生成好的私鑰文件傳送至遠程主機:
[root@linuxprobe ~]# ssh--id 192.168.10.20
The authenticity of host '192.168.10.20 (192.168.10.20)' can't be established.
ECDSA key fingerprint is 4f:a7:91:9e:8d:6f:b9:48:02:32:61:95:48:ed:1e:3f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh--id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh--id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:此處輸入遠程伺服器主機密碼
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.20'"
and check to make sure that only the key(s) you wanted were added.

第3步:設置伺服器主機只允許密鑰驗證,拒絕傳統口令驗證方式,記得修改配置文件後保存並重啟sshd服務程序哦~:
[root@linuxprobe ~]# vim /etc/ssh/sshd_config
………………省略部分輸出信息………………
74
75 # To disable tunneled clear text passwords, change to no here!
76 #PasswordAuthentication yes
77 #PermitEmptyPasswords no
78 PasswordAuthentication no
79
………………省略部分輸出信息………………
[root@linuxprobe ~]# systemctl restart sshd

第4步:在客戶端主機嘗試登陸到服務端主機,此時無需輸入密碼口令也可直接驗證登陸成功:
[root@linuxprobe ~]# ssh 192.168.10.20
Last login: Mon Apr 13 19:

⑥ linux下怎樣設置ssh無密碼登錄

第1步:在本地主機中生成「密鑰對」並將公鑰傳送到遠程伺服器中:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):直接敲擊回車或設置密鑰的存儲路徑
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 直接敲擊回車或設置密鑰的密碼
Enter same passphrase again: 再次敲擊回車或設置密鑰的密碼
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
40:32:48:18:e4:ac:c0:c3:c1:ba:7c:6c:3a:a8:b5:22 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|+*..o . |
|*.o + |
|o* . |
|+ . . |
|o.. S |
|.. + |
|. = |
|E+ . |
|+.o |
+-----------------+

第2步:將生成好的私鑰文件傳送至遠程主機:
[root@linuxprobe ~]# ssh--id 192.168.10.20
The authenticity of host '192.168.10.20 (192.168.10.20)' can't be established.
ECDSA key fingerprint is 4f:a7:91:9e:8d:6f:b9:48:02:32:61:95:48:ed:1e:3f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh--id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh--id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:此處輸入遠程伺服器主機密碼
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.20'"
and check to make sure that only the key(s) you wanted were added.

第3步:設置伺服器主機只允許密鑰驗證,拒絕傳統口令驗證方式,記得修改配置文件後保存並重啟sshd服務程序哦~:
[root@linuxprobe ~]# vim /etc/ssh/sshd_config
………………省略部分輸出信息………………
74
75 # To disable tunneled clear text passwords, change to no here!
76 #PasswordAuthentication yes
77 #PermitEmptyPasswords no
78 PasswordAuthentication no
79
………………省略部分輸出信息………………
[root@linuxprobe ~]# systemctl restart sshd

第4步:在客戶端主機嘗試登陸到服務端主機,此時無需輸入密碼口令也可直接驗證登陸成功:
[root@linuxprobe ~]# ssh 192.168.10.20
Last login: Mon Apr 13 19:34:13 2017

ssh的話你可以詳細看一下http://www.linuxprobe.com/chapter-09.html#921_sshd

⑦ linux下怎樣設置ssh無密碼登錄

ssh 是一個專為遠程登錄會話和其他網路服務提供安全性的協議。默認狀態下ssh鏈接是需要密碼認證的,可以通過添加系統認證(即公鑰-私鑰)的修改,修改後系統間切換可以避免密碼輸入和ssh認證。以下將創建過程簡單介紹下。

一、用ssh-keygen創建公鑰
haifeng@haifeng-EX38-DS4:/$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/haifeng/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/haifeng/.ssh/id_rsa.
Your public key has been saved in /home/haifeng/.ssh/id_rsa.pub.
The key fingerprint is:
7b:75:98:eb:fd:13:ce:0f:c4:cf:2c:65:cc:73:70:53 haifeng@haifeng-EX38-DS4
The key's randomart image is:
+--[ RSA 2048]----+
| E|
| .|
| ...|
| + =.|
| S + +.*|
| . . + Bo|
| . . . = =|
| . . . * |
| . ..=|
+-----------------+

##輸入後,會提示創建.ssh/id_rsa、id_rsa.pub的文件,其中第一個為密鑰,第二個為公鑰。過程中會要求輸入密碼,為了ssh訪問過程無須密碼,可以直接回車 。
2.查看鑰匙。
[root@localhost .ssh]# ls ~/.ssh/
id_rsa id_rsa.pub known_hosts

###可以發現 ssh目錄下的兩枚鑰匙。
3.將公鑰復制到被管理機器上面
[root@localhost .ssh]# scp id_rsa.pub [email protected]:~/.ssh/authorized_keys
[email protected]'s password:
id_rsa.pub 100% 408 0.4KB/s 00:00

4.訪問
# ssh 192.168.36.194
The authenticity of host '<Game2> (<192.168.36.194>)' can't be established.
RSA key fingerprint is 34:b9:92:06:53:e6:91:4d:47:92:73:57:78:6a:5d:09.
Are you sure you want to continue connecting (yes/no)?yes
Warning: Permanently added '<Game2> (<192.168.36.194>' (RSA) to the list of known hosts.

這是因為首次訪問後,ssh會在.ssh/known_hosts中保存各個認證過的主機信息:
192.168.36.194 ssh-rsa +W8X8qk1CoPdzu8YcMCpw5425mai0/RxkB/+YElCgH+/8ULgaKg3LtvP+/p0ml+uuS4DO3Up2VjqoRtqtuzWExnTyAGS//YLTGF8vVvjo5w==
5.再次訪問,ssh登錄發現可以不用密碼登錄。
[root@localhost .ssh]# ssh 192.168.36.194
Last login: Fri Apr 22 00:56:45 2011 from 192.168.18.44
[root@Game2 ~]#

⑧ 如何在linux中如何配置ssh免密碼登錄

首先需要在伺服器端設置/etc/ssh/sshd_config
# vim /etc/ssh/sshd_config
修改如下兩行為yes。其實大多數情況下不用修改,默認就是yes。
RSAAuthentication yes
PubkeyAuthentication yes
(1) 如果客戶機和伺服器都是Linux機器,那麼我們使用下面的方法:(後面第2節會提到怎麼在Windows下使用Putty生成密鑰對)
我們需要在客戶端生成RSA密鑰對。使用ssh-keygen命令:
# ssh-keygen -t rsa
參數t的意思是type,後面跟著加密類型,這里我們是rsa。
然後會提示你輸入密鑰保存完成文件名,這里我們需要使用默認的id_rsa,之後才能正常才能登錄。如果你生成的密鑰作為其他用處,那麼可以命名為其他名稱:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cake/.ssh/id_rsa):
之後會提示你輸入一個passphrase,我們這里可以留空,這樣我們登錄的時候就不許輸入密碼。
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
然後會提示你密鑰生成成功。這是你的私鑰保存為~/.ssh/id_rsa,你的公鑰是~/.ssh/id_rsa.pub
我們現在需要做的是,把id_rsa.pub的內容,添加的伺服器端的~/.ssh/autherized_keys文件最後。
你可以把這個文件上傳到伺服器端,然後使用命令:
# cat id_rsa.pub >> ~/.ssh/autherized_keys
到這里就完成了。
(2) 在Windows下使用Putty生成密鑰對:
Putty的安裝目錄下有個puttygen.exe程序,我們運行這個程序。
之後點擊Generate,開始生成密鑰對。我們需要根據提示,在指定方框內隨機滑動滑鼠。這是為了根據滑鼠軌跡,產生一些隨機數據。
之後生成結束,我們點擊Save Private Key將私鑰存放在某個目錄中。然後賦值最上面文本框中的全部內容,粘貼到Linux伺服器端的autherized_key的最後。
我們現在可以關閉這個小程序。
現在打開Putty,在左邊的選項中,選擇Conneciton–SSH–Auth,在Private key file for authentication中,選擇剛才保存的私鑰路徑就可以了。
到此位置,Putty也可以不用密碼登錄了。

⑨ 怎麼可以無密碼ssh 訪問linux

1、用ssh-keygen創建公鑰
(1)在伺服器1上執行下面的命令:

[plain] view plain print?
[root@Server1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key(/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in/root/.ssh/id_rsa.
Your public key has been saved in/root/.ssh/id_rsa.pub.
The key fingerprint is:
7b:aa:08:a0:99:fc:d9:cc:d8:2e:4b:1a:c0:6b:da:e4root@Server1
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
|. |
|o. S |
|++. . |
|+=o. . . |
|o+=oB. o |
|..E==*... |
+-----------------+
輸入後,會提示創建.ssh/id_rsa、id_rsa.pub的文件,其中第一個為密鑰,第二個為公鑰。過程中會要求輸入密碼,為了ssh訪問過程無須密碼,可以直接回車 。

(2)補充說明:
ssh-keygen:生成秘鑰
其中:
-t指定演算法
-f 指定生成秘鑰路徑
-N 指定密碼

2、查看鑰匙
[plain] view plain print?
[root@Server1 ~]# ls -l .ssh
總用量 8
-rw-------. 1 root root 1675 12月 10 22:20 id_rsa
-rw-r--r--. 1 root root 394 12月 10 22:20 id_rsa.pub
可以發現 ssh目錄下的兩枚鑰匙。

3.將公鑰復制到被管理機器Server2和Server3下的.ssh目錄下(先確保存在這個目錄)
[plain] view plain print?
[root@server1 .ssh]# scp [email protected]:~/.ssh/
The authenticity of host '192.168.1.3(192.168.1.3)' can't be established.
RSA key fingerprint is93:eb:f9:47:b1:f6:3f:b4:2e:21:c3:d5:ab:1d:ae:65.
Are you sure you want to continueconnecting (yes/no)? yes
Warning: Permanently added '192.168.1.3'(RSA) to the list of known hosts.
[email protected]'s password:
id_rsa.pub
[root@server1 .ssh]# scp [email protected]:~/.ssh/authorized_keys
The authenticity of host '192.168.1.4(192.168.1.4)' can't be established.
RSA key fingerprint is93:eb:f9:47:b1:f6:3f:b4:2e:21:c3:d5:ab:1d:ae:65.
Are you sure you want to continueconnecting (yes/no)? yes
Warning: Permanently added '192.168.1.4'(RSA) to the list of known hosts.
[email protected]'s password:
id_rsa.pub
到Server2和Server3目錄下執行下面的命令

[plain] view plain print?
#cat id_dsa.pub >> ~/.ssh/authorized_keys
4、設置文件和目錄許可權:
設置authorized_keys許可權

[plain] view plain print?
$ chmod 600 authorized_keys
設置.ssh目錄許可權

[plain] view plain print?
$ chmod 700 -R .ssh
5、驗證使用SSH IP地址的方式無密碼訪問
[plain] view plain print?
[root@server1 .ssh]# ssh 192.168.1.3
Last login: Tue Dec 10 22:34:02 2013
[root@Server2 ~]#
[root@Server2 ~]#
[root@Server2 ~]#

⑩ linux下怎樣設置ssh無密碼登錄

方法/步驟

主機A:192.168.1.110

主機B:192.168.1.111

需要配置主機A無密碼登錄主機A,主機B

先確保所有主機的防火牆處於關閉狀態。

在主機A上執行如下:

1.$cd ~/.ssh

2.$ssh-keygen -t rsa --------------------然後一直按回車鍵,就會按照默認的選項將生成的密鑰保存在.ssh/id_rsa文件中。

3.$cp id_rsa.pub authorized_keys

這步完成後,正常情況下就可以無密碼登錄本機了,即ssh localhost,無需輸入密碼。

4.$scp authorized_keys [email protected]:/home/hadoop/.ssh ------把剛剛產生的authorized_keys文件拷一份到主機B上.

5.$chmod 600 authorized_keys

進入主機B的.ssh目錄,改變authorized_keys文件的許可許可權。



正常情況下上面幾步執行完成後,從主機A所在機器向主機A、主機B所在機器發起ssh連接,只有在第一次登錄時需要輸入密碼,以後則不需要。

可能遇到的問題:

1.進行ssh登錄時,出現:」Agent admitted failure to sign using the key「 .

執行: $ssh-add

強行將私鑰 加進來。

2.如果無任何錯誤提示,可以輸密碼登錄,但就是不能無密碼登錄,在被連接的主機上(如A向B發起ssh連接,則在B上)執行以下幾步:

$chmod o-w ~/

$chmod 700 ~/.ssh

$chmod 600 ~/.ssh/authorized_keys

3.如果執行了第2步,還是不能無密碼登錄,再試試下面幾個

$ps -Af | grep agent

檢查ssh代理是否開啟,如果有開啟的話,kill掉該代理,然後執行下面,重新打開一個ssh代理,如果沒有開啟,直接執行下面:

$ssh-agent

還是不行的話,執行下面,重啟一下ssh服務

$sudo service sshd restart

4. 執行ssh-add時提示「Could not open a connection to your authenticationh agent」而失敗

執行: ssh-agent bash

熱點內容
火車軟卧無線密碼是多少 發布:2024-04-19 07:38:59 瀏覽:422
vb系統文件夾 發布:2024-04-19 07:29:58 瀏覽:739
qt怎麼添加文件夾 發布:2024-04-19 07:22:53 瀏覽:255
sql查詢表是否存在 發布:2024-04-19 06:11:48 瀏覽:622
T178Tccftp 發布:2024-04-19 06:11:35 瀏覽:185
電腦遠程訪問自己的伺服器 發布:2024-04-19 00:08:03 瀏覽:96
噸包演算法 發布:2024-04-19 00:02:13 瀏覽:328
win8解壓縮軟體官方下載 發布:2024-04-18 23:52:27 瀏覽:727
手機軟體在哪個文件夾 發布:2024-04-18 23:51:26 瀏覽:373
未加密魔獸地圖 發布:2024-04-18 23:39:13 瀏覽:947