首先查看openssh-server是否啟動:
ps -e | grep ssh
如果沒有任何提示則是沒有啟動:
sudo /etc/init.d/ssh -start
啟動進程。若提示找不到命令則需要安裝openssh-server:
sudo apt-get install openssh-server
另外,openssh-client ubuntu是默認已經安裝好的,如果沒有安裝可以用以下命令安裝:
sudo apt-get install openssh-client
然后即可用scp/rsync命令傳輸文件了。
ssh username@Ubuntu’s ip (eg.192.168.0.1)
#SSH 遠程登入 Ubuntu 機
scp -r username@192.168.0.1:/home/username/remotefile.txt
#將 文件/文件夾 從遠程 Ubuntu 機拷至本地(scp)
scp -r localfile.txt username@192.168.0.1:/home/username/
#將 文件/文件夾 從本地拷至遠程 Ubuntu 機(scp)
rsync -v -u -a –delete –rsh=ssh –stats username@192.168.0.1:/home/username/remotefile.txt
#將 文件/文件夾 從遠程 Ubuntu 機拷至本地(rsync)
rsync -v -u -a –delete –rsh=ssh –stats localfile.txt username@192.168.0.1:/home/username/
#將 文件/文件夾 從本地拷至遠程 Ubuntu 機(rsync)
scp 命令可以用來通過安全、加密的連接在機器間傳輸文件。它與 rcp 相似。
把本地文件傳輸給遠程系統的一般語法是:
scp localfile username@tohostname:/newfilename
localfile 指定源文件,username@tohostname:/newfilename 指定目標文件。
要把本地文件 shadowman 傳送到你在 penguin.example.net 上的賬號內,在 shell 提示下鍵入(把 username 替換成你的用戶名):
scp shadowman username@penguin.example.net:/home/username
這會把本地文件 shadowman 傳輸給 penguin.example.net 上的 /home/username/shadowman 文件。把遠程文件傳輸給本地系統的一般語法是:
scp username@tohostname:/remotefile /newlocalfile
remotefile 指定源文件,newlocalfile 指定目標文件。
源文件可以由多個文件組成。譬如,要把目錄 /downloads 的內容傳輸到遠程機器 penguin.example.net 上現存的 uploads 目錄,在 shell 提示下鍵入下列命令:
scp /downloads/* username@penguin.example.net:/uploads/
參考:
http://blog.163.com/wz_pk007/blog/static/170627050201251431325833/
http://asyty.iteye.com/blog/1440141
