2018.08
30
ssh 遠程執行腳本
環境:兩臺centos 7.0 ip:192.168.1.228、192.168.1.229
從192.168.1.228免輸入密碼登錄到192.168.1.229
配置192.168.1.228
1、進入~目錄
cd ~
創建.ssh 文件夾
mkdir .ssh
chmod 700 .ssh
2、創建ssh鑰匙文件
ssh-keygen -t rsa
3、更改私有鑰匙的屬性
chmod 600 id_rsa
4、將公共鑰匙文件傳送到192.168.1.229
使用scp傳送
進入.ssh目錄中
scp id_rsa.pub ro[email protected]:~/.ssh #注意192.168.1.229中需要存在.ssh目錄
在192.168.1.229中.ssh
cat id_rsa.pub >> authorized_keys
chmod 700 .ssh
測試
在192.168.1.228中登錄到192.168.1.229
直接可以登錄成功
注意從192.168.1.229登錄到192.168.1.228是需要輸入密碼認證,如果都不需要輸入密碼,只需再192.168.1.229重復上面的步驟即可
測試在192.168.1.228中遠程調用192.168.1.229的shell命令
在192.168.1.229中的/opt/shell/下建立一個shell腳本
test.sh
內容
#!/bin/bash
mkdir /opt/shell/log
授予執行權限
chmod +x test.sh
在192.168.1.228中遠程調用
ssh [email protected] ‘bash /opt/shell/test.sh’
文章出自:CCIE那點事 http://www.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文標題:ssh 遠程執行腳本
本文鏈接:http://www.qdxgqk.live/?p=3906轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
暫時還木有人評論,坐等沙發!