scp command line เป็นการคัดลอกไฟล์อย่างปลอดภัยผ่าน ssh ระหว่างเครื่อง linux, mac, windows
โดยไม่ต้องติดตั้งอะไร หรือกำหนดค่าอะไรให้ยุ่งยาก เพียงใช้ scp command บรรทัดเดียว ก็สามารถคัดลอกไฟล์ข้ามเครื่อง server ได้ทันที
>>> มาดูวิธีใช้งาน scp command <<<
มี options ให้เลือกใช้งานดังนี้
-c cipher คือ เลือกการเข้ารหัสของข้อมูลที่ต้องการส่ง
Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh(1).
-i identity_file คือ เลือกไฟล์ที่ใช้สำหรับเก็บ key ในการ authentication
Selects the file from which the identity (private key) for RSA authentication is read. This option is directly passed to ssh(1).
-p คือ คงวันที่แก้ไขไฟล์ไว้ รวมทั้งวันที่ access times หรือ permission mode ต่างๆ ไว้ให้เหมือนเดิม
Preserves modification times, access times, and modes from the original file.
-r คือทำการ copy ข้อมูลใน sub directories ด้วย
Recursively copy entire directories.
-v คือ Verbose mode. Causes scp and ssh(1) to print debugging messages about their progress.
This is helpful in debugging connection, authentication, and configuration problems.
-B คือ เลือกเป็นโหมด batch จำทำให้ป้องกันการถามรหัสผ่าน
Selects batch mode (prevents asking for passwords or passphrases).
-q คือ ปิดการใช้งานแถบแสดงสถานะ
Disables the progress meter.
-C คือ เปิดการใช้งานการบีบอัดข้อมูล
Compression enable. Passes the -C flag to ssh(1) to enable compression.
-F ssh_config คือ ระบุค่าต่างๆ สำหรับ ssh
Specifies an alternative per-user configuration file for ssh This option is directly passed to ssh(1).
-P port คือ ระบุ port ที่จะเชื่อมต่อไปยังปลายทาง โดยตัวเลือกนี้จะต้องใช้ตัว P ใหญ่ เนื่องจาก p เล็กถูกนำไปใช้อย่างอื่นแล้ว
Specifies the port to connect to on the remote host. Note that this option is written with a capital `P’ because -p is already reserved for preserving the times and modes of the file in rcp(1).
-S program คือ ชื่อของโปรแกรมที่จะใช้ในการเข้ารหัสการเชื่อมต่อ โดยโปรแกรมจะต้องเข้าใจใน protocol ssh ด้วย
Name of program to use for the encrypted connection. The program must understand ssh(1) options.
-o ssh_option คือ Can be used to pass options to ssh in the format used in ssh_config5. This is useful for specifying options for which there is no separate scp command-line flag. For example, forcing the use of protocol version 1 is specified using scp -oProtocol=1
-4 คือ บังคับให้ scp ใช้ IPv4 เท่านั้น
Forces scp to use IPv4 addresses only.
-6 คือ บังคับให้ scp ใช้ IPv6 เท่านั้น
Forces scp to use IPv6 addresses only.
ตัวอย่างการใช้งาน scp command
กรณีต้องการส่งไฟล์ ไปยัง Server ปลายทาง
scp -C -r /home/share/all-data/IT root@192.168.0.101:/samba/All-Data
คำสั่งนี้เป็นการ copy ข้อมูลโดยรวม sub directories ด้วย จากเครื่องต้นทาง /home/share/all-data/IT คัดลอกไปยังปลายทางเครื่อง 192.168.0.101 โดยเข้าไปโดยใช้ root ในการ authenticate และนำไฟล์ copy ไปวางที่ /samba/All-Data
เสร็จขั้นตอน คำสั่ง SCP เพื่อทำการ copy ข้อมูลระหว่าง Server [Linux SCP command ]
Trip Computer