第一步
在你控制機(jī)器上(你的機(jī)器,Linux)上運(yùn)行如下命令
[root@www.linuxidc.com]~# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
7d:2a:f7:4e:87:40:ef:dd:ae:29:45:dd:2f:70:1b:ce root@www.linuxidc.com.linuxidc.net
在~/.ssh/目錄下生成id_rsa, id_rsa.pub
將id_rsa.pub拷貝至遠(yuǎn)程主機(jī)~/.ssh目錄下,并改名為authorized_keys
OK; 現(xiàn)在可以用ssh遠(yuǎn)程登錄主機(jī)了。
補(bǔ)充:
ssh-keygen 時會問Enter passphrase (empty for no passphrase):
此處直接enter 跳過,下次才不會詢問password
如果輸入密碼,下次連接遠(yuǎn)程主機(jī)時會詢問私人密碼(非root口令)
這一步的效果就是,訪問服務(wù)器的時候不需要輸入密碼,方便以后就算服務(wù)器改密碼也沒事。
第二步
去Linux公社1號服務(wù)器下載一個叫做pssh的軟件(python寫的哦)
下載地址:
FTP地址:ftp://www.linuxidc.com
用戶名:www.linuxidc.com
密碼:www.muu.cc
在 2011年LinuxIDC.com\2月\一個人管理上百臺甚至上千臺Linux服務(wù)器
下載方法見 http://www.linuxidc.net/thread-1187-1-1.html
然后安裝就不說了,接著修改下環(huán)境變量
[root@www.linuxidc.com]~/.ssh# vi /etc/profile
內(nèi)容如下:
export PSSH_HOSTS="/root/servers.txt"
export PSSH_USER="root"
export PSSH_PAR="32"
export PSSH_OUTDIR="/tmp"
export PSSH_VERBOSE="0"
export PSSH_OPTIONS="UserKnownHostsFile /root/.ssh/known_hosts"
簡單介紹下,第1行就是記錄要控制的服務(wù)器的IP。
然后執(zhí)行如下命令讓環(huán)境變量生效
[root@www.linuxidc.com]~/.ssh# source /etc/profile
然后在/root目錄下新建一個文件,把要管理的服務(wù)器IP都寫在里面。
[root@www.linuxidc.com]~#cat servers.txt
192.168.100.240
65.111.169.35
然后測試下能不能連的上服務(wù)器
[root@www.linuxidc.com]~# pssh uptime
Success on 192.168.100.240:22
Success on 65.111.169.35:22
如果是success就表示成功,error當(dāng)然就是失敗了。
第三步
OK,經(jīng)過前面的配置,激動人心在時刻來了,執(zhí)行如下命令:
[root@www.linuxidc.com]~# pssh -h /root/servers.txt -l root -o /tmp/foo uptime
Success on 192.168.100.240:22
Success on 65.111.169.35:22
簡單介紹下 -h 就是服務(wù)器IP的文件 -l 就是用戶名 -o 就是把uptime執(zhí)行的結(jié)果返回到/tmp/foo目錄下。
接下來,我們試下關(guān)閉服務(wù)器的 sendmail
[root@www.linuxidc.com]~# pssh service sendmail stop
Success on 192.168.100.240:22
Success on 65.111.169.35:22
OK,提示成功,去服務(wù)器看下,沒問題,搞定了。
第四步
給服務(wù)器同時上傳一樣的文件,簡單做到
[root@www.linuxidc.com]/var# pscp -h /root/servers.txt -l root /var/haha.txt /var/haha.txt
Success on 192.168.100.240:22
Success on 65.111.169.35:22
說下,就是把本機(jī)的/var/haha.txt 傳到服務(wù)器的/var目錄。
億恩科技地址(ADD):鄭州市黃河路129號天一大廈608室 郵編(ZIP):450008 傳真(FAX):0371-60123888
聯(lián)系:億恩小凡
QQ:89317007
電話:0371-63322206 本文出自:億恩科技【www.allwellnessguide.com】
服務(wù)器租用/服務(wù)器托管中國五強(qiáng)!虛擬主機(jī)域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|