Remote computer control is the ability to control a computer and use its functions from a distance, using another computer, smartphone or remote control. This distance can range from several meters to thousands of kilometers. Remote control of a computer is impossible without the use of special software – remote control programs. These are programs or functions of operating systems that allow remote access to a computer and control and administration of a remote computer in real time. Remote administration programs provide almost complete control over a remote computer: they provide the ability to remotely control the computer’s desktop, the ability to copy or delete files, launch applications, and more. It is useful for many scenarios, for example, for remote access to a computer from anywhere in the world, for training, for assisting technically challenged users, or for working with a computer that is located in another location.
The OpenSSH package includes two programs that use an encrypted SSH tunnel to copy files over the network. The first program – scp (“secure copy”) is similar to the cp program for copying files. The second program for copying files over SSH is sftp. As its name suggests, it is a secure replacement for ftp programs. sftp works like the original ftp program. However, instead of sending data in plain text, it uses an encrypted SSH tunnel. An important advantage of sftp over ftp is that it does not require a running FTP server on the remote host. It only requires an SSH server. This means that any remote machine running an SSH server can also be used as an FTP-like server.
- work through an SSH connection
- transmit data through encrypted channels
- do not require a special server or programs on the remote machine except the SSH server
- use all the features of SSH, such as public key authentication and compression of the data being transmitted.
- popular file managers understand the sftp protocol and can integrate with this command
- sftp supports batch mode – files in which the sequence of actions is determined by the sequence of sftp commands
- when recursively downloading or uploading folders, by default scp follows symbolic links and sftp does not
- sftp is able to add partially transferred files if an interruption occurred during the transfer of a large file (configurable with an option)
- scp does not work in interactive mode, while sftp can work in interactive mode and in auto-interactive mode
- sftp supports the syntax of FTP commands for various actions in the file system (copying and moving files, creating and deleting files and folders, etc.)
The scp utility is very similar to the cp program, which copies files within the local computer. It is important to understand the key gist of scp syntax:
That is, there are only three elements in the team. The source file can be both a file on the local system and on a remote one. Similarly, the destination can be both a file on the local system and on a remote one. The path to the local file is specified in the usual way – the same as with the cp program.
A file on the remote system can be specified as follows:
Or as a URI in the form:
So, if we copy a file from a remote system to a local one, the general command looks like this:
As ./PATH/IN/LOCAL/SYSTEM you can specify simply . (dot) and then the file will be copied with the current name to the current working directory.
If we are copying a file from a local system to a remote one, the general view of the command is as follows:
The syntax of accessing a remote host is similar to SSH: USER@HOST, the only difference is that the path to the file (or just the file name) is indicated after the colon. When using a URI, the colon is followed by the port (if it is different from the default), and the file path is followed by the slash. Consider an example of executing a command on a remote system and downloading this file to the local system:
In the scp command, the OUTPUT-FILE is marked as [email protected]:dirlist.txt – here the colon is followed by the username on the remote system and the host address – and the information that is necessary for connecting via SSH. Then the file to be downloaded is separated by a colon. DESTINATION in this command is marked as . (dot) – which means the current working directory (on the local system).
Now consider an example of copying a file from a local machine to a remote one:
- nfile.txt – file name,
- [email protected] – username and remote host (as in the SSH connection command),
- . (точка) means that the file should be copied to the current working directory on the remote server, leaving the file name unchanged, i.e. nfile.txt
For recursive copying of entire directories, use the -r option. Remember that scp follows symlinks encountered while traversing the directory tree.
Using the -p option (not to be confused with the -P option, which changes the connection port), you can preserve the modification time, last access time of the file, and modes of the original file.
By default, the file is transferred at the maximum possible speed. If for some reason you need to reduce the speed limit, use the -l option, followed by the value in Kbit/s.
You can specify another port using the -P PORT option. Note that this option is capitalized ‘P‘ because -p is already used for another setting (preserving time and file modes).
We can also copy a file from one remote host to another remote host. The scp program can copy between two remote hosts. If the URI format is used, the port can only be specified for the target if the -3 option is used. By default, data is copied directly between two remote hosts. If the -3 option is specified, data between the two hosts will be transferred via the local host. This option disables the progress bar.
We can also use another configuration file for scp and specify the authentication keys file. The scp program works together with ssh, that is, the connection is made using ssh and all the settings of this program are applied. ssh has its own default settings, and it also reads information from its configuration files. If desired, you can specify a different file to use, this is done with the -F option – it specifies an alternative user configuration file for ssh. This option is passed directly to ssh. If passwordless (by key) login is configured, ssh will read the private key according to its settings or from the default path. The -i option can be used to select a different identifier (private key) file to authenticate against the public key on the server. This option is also passed directly to ssh.
Disabling strict filename checking can be done with the -T option. By default, when copying files from a remote host to a local directory, scp checks that the corresponding filenames match those requested on the command line to prevent the remote host from sending unexpected or unwanted files. Due to differences in how different operating systems and shells interpret file name wildcards, these checks can cause the correct files to be rejected. This option disables these checks at the cost of fully trusting that the server will not send unexpected filenames.
The -q option enables quiet mode: disables the progress bar, as well as warning and diagnostic messages from ssh.
The destination can be specified as [USER@]HOST[:PATH] or as a URI of the form sftp://[USER@]HOST[:PORT][/PATH] If the destination contains a PATH that is a directory, sftp will automatically receive the files , if a non-interactive authentication method is used; otherwise, it will be done after successful interactive authentication. If no path is specified or the path is a directory, sftp will log on to the specified host and enter interactive command mode, navigating to the remote directory if one was specified. An optional trailing slash can be used to force a path to be interpreted as a directory.
When entering interactive mode, sftp understands a set of commands similar to those for ftp(1). Commands are not case sensitive. Paths and file names that contain spaces must be enclosed in quotation marks. Any special characters contained within pathnames recognized by glob(3) must be escaped with a backslash (”).
SCP and SFTP are not only utilities, but also protocols. That is, other programs can support work with them and be used as a convenient graphical interface. Thanks to this, you will be able to manage files on the server, for example, through FileZilla or the usual file managers.