CentOS 6.7實戰部署SSHKey

來源:互聯網
上載者:User

標籤:sshkey

部署環境:

準備兩台(或兩台以上)CentOS 6.7 X86_64伺服器

其中IP地址為10.0.0.7為SSHKey分發機

1、每台伺服器建立使用者wanyuetian,並建立密碼123456

[[email protected] ~]# useradd wanyuetian [[email protected] ~]# echo 123456|passwd --stdin wanyuetianChanging password for user wanyuetian.passwd: all authentication tokens updated successfully.

2、在分發機(10.0.0.7)建立金鑰組

[[email protected] scripts]# su - wanyuetian[[email protected] ~]$ ssh-keygen -t dsa     #一路斷行符號[[email protected] ~]$ ls -l .ssh/total 8-rw------- 1 wanyuetian wanyuetian 672 Oct 22 16:07 id_dsa-rw-r--r-- 1 wanyuetian wanyuetian 608 Oct 22 16:07 id_dsa.pub

3、分發公開金鑰(以10.0.0.8為例,其他相同),SSH的連接埠為22

[[email protected] ~]$ ssh-copy-id -i .ssh/id_dsa.pub [email protected]

如果SSH連接埠不是22,使用命令ssh-copy-id -i .ssh/id_dsa.pub "-p 52113 [email protected]"

[[email protected] ~]# ll /home/wanyuetian/.ssh/-rw------- 1 wanyuetian wanyuetian 608 Oct 22 16:11 authorized_keys


id_dsa.pub分發後,在其他用戶端名字變為authorized_keys,內容沒有發生改變,所以可以在服務端改名後打包分發或放到web伺服器給其他伺服器提供下載,注意authorized_keys檔案的許可權要一定為600
4、測試遠程執行命令

[[email protected] ~]$ ssh -p22 [email protected] /sbin/ifconfig eth0eth0      Link encap:Ethernet  HWaddr 00:0C:29:F6:A2:78            inet addr:10.0.0.8  Bcast:10.0.0.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fef6:a278/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:41966 errors:0 dropped:0 overruns:0 frame:0          TX packets:24455 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:5163110 (4.9 MiB)  TX bytes:3706021 (3.5 MiB)

Ps:到此,SSHKey部署完成,本案例我是用普通使用者做的,所以安全性較高,但是進行批量管理以及分發檔案時較為不便,需要root做sudo授權。如果不考慮安全性,可以直接使用root使用者部署。

SSHKey適合小規模叢集環境的部署和管理(即伺服器只有幾十台左右),如果伺服器較多,可以考慮使用Saltstack進行批量管理。

本文出自 “萬越天的架構師之路” 部落格,請務必保留此出處http://wanyuetian.blog.51cto.com/3984643/1717055

CentOS 6.7實戰部署SSHKey

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.