個人電腦連接遠程服務器點滴

  1. ssh配置遠程登錄別名:
    cd ~/.ssh 在config文件中:添加這句話
#remote server config
Host pit  #別名
HostName 123.207.170.77
User root
IdentitiesOnly yes #默認

舉例:ssh pit 然後輸入密碼就行了
提示:默認遠程服務器不開通密碼登錄,需要在遠程服務器上的.ssh/authorized_keys文件中,修改PasswordAuthentication爲yes,然後重啓服務器就行了。

  1. 文件操作
# 將本地文件上傳到遠程服務器上
scp Desktop/sunshine.sql pit:/root/Desktop
# 將遠程服務器目錄下載到本地目錄
scp -r username@servername:/remote_dir/(遠程目錄) local_dir(本地目錄)

shell 自動化上傳下載文件demo

#!/usr/bin/expect -f
set password ?
#download
spawn scp root@ip:/root/Desktop/sunshine.sql  /Users/chenpeng/Desktop
set timeout 300
expect "root@ip's password:"
set timeout 300
send "$password\r"
set timeout 300
send "exit\r"
expect eof

expect使用介紹
expect命令詳解
可輸入參數示例

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章