Copy หรือ Dowload ไฟล์ด้วยคำสั่ง SCP กรณีใช้ Private Key

Sathit Seethaphon
Sathit Seethaphon
Published in
1 min readOct 31, 2016

--

ปกติ copy ไฟล์จากเครื่องไป server หรือ download ไฟล์จากเครื่อง server ผมชอบใช้ scp เพราะสะดวกดี วันนี้เจอปัญหาว่าในกรณีที่เราใช้ private key ในการ login จะทำยังไงลองค้นดูแค่เพิ่ม option -i เข้าไป

Download ไฟล์จาก Server

scp -i ~/path/key user@xxx.xx.xx.xx:<pathFileFromServer> <localPath>

ตัวอย่างการใช้งาน

scp -i ~/ssh/user.key.openssh dixon@192.168.34.99:~/apps/backup-11-17-2016_16-43.sql ~/Downloads/

Copy ไฟล์ไปที่ Server

scp -r -i <private key path> <local file path> user@ip:<path to destination>

ตัวอย่าง

scp -r -i ~/ssh/test.openssh data/db.sql user@192.168.99.99:~/apps/files/db.sql

จบข่าว ^^

ที่มา http://stackoverflow.com/questions/20939562/scp-permission-denied-publickey-on-ec2-only-when-using-r-flag-on-directories

--

--