К основному контенту

Примеры использования scp для копирования файлов


Программа scp позволяет безопасно копировать файлы между двумя компьютерами под управлением Linux или Unix. Для трансфера используется ssh со всеми вытекающими: такие же способы аутентификации, как в ssh, и такая же степень защиты.
Примеры использования синтаксиса scp
С помощью scp скопируем файл «testfile.txt» с удаленного хоста на локальный:
$ scp username@remotehost.ru:testfile.txt /local/directory
В данном случае можно воспользоваться вместо /local/directory той же ~ для обозначения домашнего каталога.


Скопируем файл «testfile.txt» с локального хоста на удаленный при помощи scp:
$ scp testfile.txt username@remotehost.ru:/remote/directory
Тоже самое касаемо ~ в качестве домашней директории пользователя на удаленном хосте — этот знак можно использовать вместо /remote/directory
Скопируем директорию «localdir» со всем ее содержимым с локального хоста в директорию «remotedir» на удаленном компьютере:
$ scp -r localdir your_username@remotehost.ru:/remote/directory/remotedir
Безопасно скопируем файл «testfile.txt» с одного удаленного хоста под названием «remotehost1.ru» на удаленный компьютер под названием «remotehost2.ru»:
$ scp username@remotehost1.ru:/remote/directory/testfile.txt username@rh2.ru:/remote/directory/
Хочу обратить внимание, что эта команда будет работать, например, между серверами на CentOS, но у меня в том случае, когда remotehost1 был под управлением Ubuntu, ничего не выгорело. На этот счет на launchpad уже есть соответствующий баг. Может быть я где-то заблуждаюсь, поэтому буду рад, если меня поправят.
Скопируем файлы test.txt и file.txt с локального компьютера в свою домашнюю директорию на удаленном хосте:
$ scp test.txt file.txt username@remotehost.ru:~
Скопируем несколько файлов test1.txt, test2.txt, test3.txt с удаленного хоста в свою домашнюю директорию локального компьютера:
$ scp username@remotehost.ru:/remote/directory/\{test1.txt,test2.txt,test3.txt\} ~
По поводу производительности scp: по умолчанию scp использует алгоритм Triple-DES для шифрования передаваемых данных, но если использовать Blowfish, то можно добиться более высокой скорости передачи данных. Для этого нужно добавить ключ -c blowfish:
$ scp -c blowfish testfile.txt username@remotehost.ru:~
Также для повышения скорости передачи данных рекомендуется использовать компрессию (сжатие). За это отвечает ключ -C, но, конечно же, увеличится нагрузка на процессор.
Пример использования scp с шифрованием алгоритмом blowfish и компрессией данных:
$ scp -c blowfish -C local_testfile.txt username@remotehost.ru:~
Вроде бы нигде ничего не напутал.

Комментарии

Популярные сообщения из этого блога

How to do Arithmetic Operations in Ansible

You can use arithmetic calculations in Ansible using the Jinja syntax. This is helpful in many situations where you have stored the output of an operation, and you need to manipulate that value. All usual operation like addition, subtraction, multiplication, division, and modulo are possible. Let us start with an example. We will be using the  debug module  to print the out the result. The following tasks show all the basic arithmetic operations. The output is given in comments. Ansible arithmetic operation example - hosts: loc tasks: - debug: msg: "addition{{ 4 +3 }}" #Ansible addition 7 - debug: msg: "substraction {{ 4 - 3 }}" #Ansible arithmetic substraction 1 - debug: msg: "multiplication {{ 4 * 3 }}" #multiplication 12 - debug: msg: "Modulo operation {{ 7 % 4}}" #ansible Modulo operation - find remainder 3 - debug: msg: "floating division {{ 4 / 3}}" #ansible floating divisio...

ubuntu/debian ipmi

#install ipmitool (this is for debian) apt-get install ipmitool #insert the kernel modules needed for ipmi modprobe ipmi_devintf modprobe ipmi_si modprobe ipmi_msghandler #get the current mode (01 00 is dedicated mode) ipmitool raw 0x30 0x70 0x0c 0 #send the raw command to enable dedicated lan ipmitool raw 0x30 0x70 0xc 1 1 0
Ansible - Appending to lists and dictionaries  n this blog post I'll show how to add items to lists and dictionaries, when using loops, and across tasks. Normally when trying to add a new item to the variable, while in the loop, or between tasks, Ansible will ovewrite the values, keeping the result of the last iteration. For example, let's see what will be the result of running the following playbook: --- - name: Append to list hosts: localhost vars: cisco: - CiscoRouter01 - CiscoRouter02 - CiscoRouter03 - CiscoSwitch01 arista: - AristaSwitch01 - AristaSwitch02 - AristaSwitch03 tasks: - name: Add Cisco and Airsta devices to the list set_fact: devices: "{{ item }}" with_items: - "{{ cisco }}" - "{{ arista }}" - name: Debug list debug: var: devices verbosity: 0 [przemek@quasar blog]$ ansible-playbook append_list.yml PLAY [Append to list] ****************...