centos7 實現ssh免密登入

2021-09-25 11:28:29 字數 1557 閱讀 5330

1、三颱虛擬機器關閉防火牆

systemctl stop firework

setenforce 0

10.254.50.30

test0

10.254.50.31

test1

10.254.50.32

test2

2、vim /etc/hosts 追加所有ip和網域名稱

10.254.50.30	test0

10.254.50.31 test1

10.254.50.32 test2

3、首先操作test0

ssh-keygen -t rsa -p ''      # 生成金鑰對,預設存在/root/.ssh/ 下
4、把公玥追加到授權的key裡面去

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

chmod 600 ~/.ssh/authorized_keys

vim /etc/ssh/sshd_config

rsaauthentication yes # 啟用 rsa 認證

pubkeyauthentication yes # 啟用公鑰私鑰配對認證方式

authorizedkeysfile .ssh/authorized_keys # 公鑰檔案路徑

5、重啟ssh

systemctl restart sshd

# 測試一下

ping localhost

# 可以無密碼登入本機

6、 上面實現了本機無密碼登入,現在把公玥複製到所有虛擬機器上

scp ~/.ssh/id_rsa.pub [email protected]:~/       #   test1

scp ~/.ssh/id_rsa.pub [email protected]:~/ # test2

7、去test1 和 test2 上 (~/ 目錄下已經有id_rsa.pub了)

mkdir ~/.ssh

chmod 700 ~/.ssh

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

chmod 600 ~/.ssh/authorized_keys

vim /etc/ssh/sshd_config # 一定要是root使用者

rsaauthentication yes # 啟用 rsa 認證

pubkeyauthentication yes # 啟用公鑰私鑰配對認證方式

authorizedkeysfile .ssh/authorized_keys # 公鑰檔案路徑

# 重啟 ssh

systemctl restart sshd

8、此時用test0去連線test1和test2

ssh test1

ssh test2

# 可以免密登入

Centos7 單機 SSH免密登陸

1.安裝 yum install openssh server2 配置 sudo vim etc ssh sshd config去掉以下內容前的 符號,其他內容不需要修改 port 22 addressfamily any listenaddress 0.0.0.0 listenaddress pe...

centos7中ssh免密登入配置

先附一張成功後應該存在的檔案 1 在 root ssh下面新建檔案authorized keys touch root ssh authorized keys2 生成金鑰 成功後會生成如下檔案 3 使用ssh登入到其他伺服器 主機名或者ip位址都可以 ssh master4 複製登入金鑰 ssh c...

centos7免密登入

1.生成秘鑰 ssh keygen t rsa 注意事項 在liunx環境下,要想複製公鑰或是私鑰,不要使用vim等編輯器開啟檔案來複製貼上 因為它會產生不必要的回車。應該使用cat把內容列印到終端上再來複製貼上 2.用 ssh copy id 把公鑰複製到遠端主機上 ssh copy idwumi...