Linux transfer files via ssh

How to Transfer Files using SCP Command in Ubuntu Linux

This article describes the steps to transfer files via SCP remotely in Ubuntu Linux.

SCP (secure copy) is a command-line utility that securely copies files and directories between two locations, either remotely or locally, on the same host.

If you ever need to transfer files quickly between two Ubuntu servers, the best way is via SSH using Secure Copy (SCP).

SCP uses SSH encryption and authentication to quickly and securely transfer files between servers. Secure copy is a means of securely sharing files and folders between two locations.

How to transfer files to a remote host via SCP in Ubuntu Linux

Run the example commands below to transfer a file to a remote server from the local server you’re currently logged into.

scp file_to_transfer.txt root@remotehost.com:/directory_to_drop_file/location/

The commands above copy a local file from the local server, transfer it to a remote server via the server’s hostname or IP address and drop it into the specified directory location.

How to transfer files from a remote host via SCP in Ubuntu Linux

You use the example commands below to transfer files from a remote host to a local server. Let’s say you want to copy your entire website content into a zipped folder called website_content.zip .

You run the commands below to copy the content from the remote server to the local host.

scp root@remotehost.com:/directory/website_content.zip /path_to_store_content/www/html/website_content.zip

Doing the above will copy the remote content to the local host securely. Next, replace remotehost.com with the hostname or the IP address of the remote server. Also, replace the root with the existing admin account of the server.

For some reason, if the SSH default port is changed from 22, you may have to specify the new port when using the commands above. The example command is shown below.

scp -P 2221 local_file.txt username@remotehost:/directory/location/

Do the same when copying files from the remote host to the local server.

Читайте также:  Менеджер дисплеев kali linux gdm3 lightdm sddm

This post showed you how to transfer files between two networked systems using SCP. Suppose you find any error above or have something to add, please use the comment form below.

Richard W

I love computers; maybe way too much. What I learned I try to share at geekrewind.com.

Источник

How to transfer files remotely using SSH

Secure Shell (SSH) is a versatile protocol that enables secure access to remote computers. With its scp utility, you can transfer files between remote systems efficiently, using a syntax similar to the cp command.

Additionally, SSH can be utilized by other file transfer applications like sftp and rsync to ensure secure transfers.

Examples for the following file transfer methods are based on the above setup.

Make sure you have SSH access to the remote server with adequate permission to the remote files and folders.

Methods for remote file transfer using SSH:

Transfer file using scp

scp (secure copy) is the simplest method for transferring files remotely. It requires SSH access to the remote server and operates like the cp command but for remote transfers. When using scp, you must specify the remote host’s DNS name or IP address and provide login credentials. You can use scp for local-to-remote and remote-to-local transfers.

$ scp myfile.txt remoteuser@remoteserver:/remote/folder/

If the target folder (/remote/folder/) is not specified, it will copy the file to the remote user’s home directory.

$ scp remoteuser@remoteserver:/remote/folder/remotefile.txt localfile.txt

Using . as the copy target (replacing localfile.txt will copy the remote file to the current working directory using the same filename (remotefile.txt)

$ scp myfile.txt myfile2.txt remoteuser@remoteserver:/remote/folder/
$ scp * remoteuser@remoteserver:/remote/folder/
$ scp -r * remoteuser@remoteserver:/remote/folder/

GUI programs such WinSCP can also be used to transfer files between local and remote host using scp methods.

Transfer file using sftp

Secure FTP (sftp) functions similarly to FTP , but with a secure connection. Most commands are interchangeable between the two. The following sftp examples demonstrate the similarities to standard FTP commands:

$ sftp user@192.168.1.10 Connected to 192.168.1.10. sftp> dir file1 file2 file3 sftp> pwd Remote working directory: /home/user sftp> get file2 Fetching /home/user/file2 to file2 /home/user/file2 100% 3740KB 747.9KB/s 00:05 sftp> bye $

WinSCP can also be used for file transfer using SFTP protocol, but with graphical interface. The other popular tool is FileZilla.

Transfer file using rsync

To secure your rsync sessions with SSH, use —rsh=ssh or -e ssh alongside your usual rsync commands. The two commands below produce the same results:

$ rsync -av --delete --rsh=ssh /path/to/source remoteuser@192.168.1.10:/remote/folder/ $ rsync -av --delete -e "ssh" /path/to/source remoteuser@192.168.1.10:/remote/folder/

If these options aren’t specified, rsync will first attempt to connect to rsyncd. If rsyncd isn’t running on the remote system, it will automatically revert to SSH.

Mount remote filesystem locally

You can mount remote filesystems on your local host and access them as if they were local. To do this, you’ll need SSH access to the remote host and the sshfs utility.

Читайте также:  Nvidia 460 driver linux

Источник

SSH / TransferFiles

Another important function of SSH is allowing secure file transfer using SCP and SFTP.

Secure Copy (scp)

Just as all modern Unix-like systems have an SSH client, they also have SCP and SFTP clients. To copy a file from your computer to another computer with ssh, go to a command-line and type:

For example, to copy your TPS Reports to Joe’s Desktop:

scp "TPS Reports.odw" joe@laptop:Desktop/

This will copy TPS Reports.odw to /home/joe/Desktop, because SCP uses your home folder as the destination unless the destination folder begins with a ‘/’.

To copy the pictures from your holiday to your website, you could do:

scp -r /media/disk/summer_pics/ mike@192.168.1.1:"/var/www/Summer 2008/"

The -r (recursive) option means to copy the whole folder and any sub-folders. You can also copy files the other way:

scp -r catbert@192.168.1.103:/home/catbert/evil_plans/ .

The ‘.’ means to copy the file to the current directory. Alternatively, you could use secret_plans instead of ‘.’, and the folder would be renamed.

Secure FTP (sftp)

Finally, if you want to look around the remote machine and copy files interactively, you can use SFTP:

This will start an SFTP session that you can use to interactively move files between computers.

SSHFS

SSHFS is a recent addition to Linux that allows you to make a remote filesystem available over SSH act as if it was inside a folder on your own system. See SSHFS for details.

GNOME

Click File -> Connect to Server. Select SSH for Service Type, write the name or IP address of the computer you’re connecting to in Server. Click Add Bookmark if you want to make the connection available later in the Places sidebar. There are options to login as a different User Name, on a different Port number, and use a different default Folder.

Files can be copied by dragging and dropping between this window and other windows.

KDE

Open Konqueror, and in the address bar type:

fish://username@server_address

Files can be copied by dragging and dropping them between this window or tab and to other windows or tabs.

Using other programs

SecPanel and PuTTY also have file transfer utilities, although they’re generally not as easy to use as the ones discussed above.

SSH/TransferFiles (последним исправлял пользователь c-71-237-198-100 2015-01-16 00:19:38)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

Копирование файлов через SSH

В статье мы расскажем, как копировать файлы в Windows и Linux-системах, и покажем основные команды, с помощью которых происходит передача файлов по SSH.

Читайте также:  Запустить вов на линуксе

Для копирования файлов по SSH в Linux-системах и Windows используют разные инструменты:

  • scp (Secure CoPy) — утилита для безопасного копирования данных между Linux-системами по протоколу SSH. Она входит в состав OpenSSH, поэтому для работы с утилитой не нужно устанавливать дополнительное ПО;
  • pscp.exe — утилита для загрузки файлов по SSH в ОС Windows. Она обладает теми же возможностями, что и scp. Утилита входит в состав программы Putty — SSH-клиента для Windows. Скачать программу можно по ссылке.

Если файл, который вы хотите скопировать, уже существует на целевом хосте, при копировании он будет перезаписан.

Копирование файлов по SSH на Linux

Для Linux копирование файлов по SSH происходит с использованием команды scp. С её помощью можно копировать файлы:

  • с локального компьютера на удалённый сервер,
  • с удалённого сервера на локальный компьютер,
  • с одного удалённого сервера на другой.
scp [опция] [источник] [получатель]

Как скопировать файл по SSH с локальной машины на удалённый сервер

Как загрузить файл на сервер по SSH? Для этого используйте команду вида:

scp [путь к файлу] [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу]
scp /home/test.txt root@123.123.123.123:/directory

Файл test.txt будет скопирован на хост 123.123.123.123 в директорию «/directory».

Как скопировать файлы с удалённого сервера на локальный компьютер

При подключённом SSH скачать файл на локальный компьютер с удалённого сервера можно с помощью команды:

scp [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу] [путь к файлу]
scp root@123.123.123.123:/home/test.txt /directory

Файл test.txt будет загружен с сервера 123.123.123.123 на локальный компьютер в папку «/directory».

Как скопировать файл по SSH с одного удалённого сервера на другой

Подключитесь по SSH к серверу, на котором расположен файл. Затем выполните команду:

scp [путь к файлу] [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу]
scp /home/test.txt root@123.123.123.123:/directory

Файл test.txt будет скопирован на хост 123.123.123.123 в директорию «/directory».

Как скачать папку со всеми файлами и подпапками

Если вы хотите скачать папку со всеми файлами и подпапками, используйте ключ -r:

scp -r [источник] [получатель]

Как подключиться к серверу по нестандартному порту

Бывает, что для подключения по SSH нужно указать нестандартный порт. Без указания порта команда подключается к серверу по стандартному 22 порту. Чтобы указать нестандартный порт, введите команду с ключом -P:

scp -P [источник] [получатель]
scp -P 12345 /home/test.txt root@123.123.123.123:/directory

Эта команда подключается по порту 12345 к серверу 123.123.123.123 и копирует на него файл «test.txt» с локального компьютера в директорию «/directory».

Как передать и скачать файлы по SSH на Windows

Скопировать файл по SSH на сервер можно командой:

pscp [путь к файлу] [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу]

Скачать файл по SSH с сервера командой:

pscp [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу] [путь к файлу]

Увидеть список папок и файлов на сервере можно через pscp.exe. Для этого введите:

pscp -ls [имя пользователя]@[имя сервера/ip-адрес]:[путь]

Если в пути или в названии файла есть пробелы, используйте кавычки:

pscp “C:\files or docs\file name” root@123.123.123.123:/home

Источник

Оцените статью
Adblock
detector