One of the primary ways to manage *nix servers is via establishing an SSH connection to the server. A distant server must often have files uploaded to it, and the only available method is an SSH connection. Fortunately, copying files over a secure connection is one of the protocol’s usual tasks, and it is done using the standalone scp command on Linux systems or the pscp.exe program that comes with the Putty SSH client for Windows.
Working with the Linux OS is what we do.
The format of our commands is as follows:
scp [модификатор] [источник] [место_назначения]
The format of the argument is as follows whether the source or destination is a remote server:
[пользователь]@[сервер]:[путь_к_файлу]
After running the command, you will need to enter the password for the specified remote server account.
Putting it all together, you can copy the local file /home/user/file.tgz to the home directory of the root user of the remote server 123.123.123.123 with the command:
scp /home/user/file.tgz root@123.123.123.123:/root
To download the same file from a remote server:
scp root@123.123.123.123:/root/file.tgz /home/user
You can copy several files in one operation, for this you need to specify them as a source, separated by a space – the last specified parameter will be considered the destination. For example, to upload files file1.tgz and file2.tgz from a local directory to a remote server, the command will allow:
scp file1.tgz file2.tgz root@123.123.123.123:/root
To copy a directory, you need to use the command modifier – r . Copy the local directory /home/user/dir to the remote server:
scp –r /home/user/dir root@123.123.123.123:/root
In cases where the SSH server is running on a non-standard port, the -P option will help . If you need to connect through port 10022:
scp –P 10022 /home/user/file.tgz root@123.123.123.123:/root
To find out what other modifiers the command supports, you can simply run scp without parameters and read the brief help.
We work on the Windows operating system
When using the Windows operating system and Putty as a client, the command format remains the same, only the name of the executable file changes, and the syntax for specifying paths to files and directories of Windows is used when specifying the source or destination. We start the command line (cmd.exe) or PowerShell, go to the directory where the pscp.exe file is located, enter the command:
pscp.exe C:Tempfile.tgz root@123.123.123.123:/root
If you run from any other folder, you will need to specify the full path to pscp.exe. If there are spaces in any of the paths, double quotes are used – “File path”:
“C:Program FilesPuttypscp.exe” C:Tempfile.tgz root@123.123.123.123:/root
As with scp, by running pscp. exe without parameters, you can see a brief help on the command syntax and a list of supported modifiers.
Running commands on a remote server via SSH connection
The SSH protocol, in addition to working in interactive mode, also supports a one-time launch of commands or scripts on a remote server.
We work on Linux operating system
Command syntax:
ssh [пользователь]@[сервер] ‘[команда]’
When prompted, we enter the password of the specified user and in the console we get the output of the command, if any.
For example, let’s get information about the operating system installed on the remote server:
ssh root@123.123.123.123 ‘uname -a’
To run multiple commands in one connection, you can use the symbol “;” as a separator. Let’s check the network settings and active network connections on the remote server:
ssh root@123.123.123.123 ‘ifconfig; netstat -anp tcp’
If you need to run a local script file on a remote server, you will need to call the command interpreter in the script execution mode in the SSH connection (for example, bash with the -s switch), and pass the script file to it on standard input. This design will look like this:
ssh root@123.123.123.123 ‘bash -s’
As a result, the local file /home/user/myscript.sh will be executed on the remote server.
Running the SSH command without parameters will give you a brief syntax reference and a list of additional modifiers that allow you to extend the functionality of the command.
We work on the Windows operating system
If we connect to a remote server from a computer running on the Windows operating system, then we will again need to contact the Putty terminal client, which includes the plink.exe executable file. You must work with this file from the command line (cmd.exe) or from PowerShell.
To run a command on a remote server, use the following syntax:
plink.exe [сервер] -ssh -l [пользователь] “[команда]”
Let’s examine the network interface configuration:
plink.exe 123.123.123.123 -ssh -l root “ifconfig”
Plunk.exe allows you to run several commands simultaneously by using the separator “;,” just like the Linux SSH command does:
plink.exe 123.123.123.123 -ssh -l root “ifconfig; netstat -anp tcp”
And an extra key, m, may be used to execute instructions from a local file:
plink.exe 123.123.123.123 -ssh -l root -m “C:Tempmyscript.sh”
You may read a quick syntax reference and a list of other command modifiers by executing the plink.exe command without any arguments.
Welcome to the world of DomainRooster, where roosters (and hens) rule the roost! We're a one-stop shop for all your entrepreneurial needs, bringing together domain names and website hosting, and all the tools you need to bring your ideas to life. With our help, you'll soar to new heights and hatch great success. Think of us as your trusty sidekick, always there to lend a wing and help you navigate the sometimes-complex world of domain names and web hosting. Our team of roosters are experts in their fields and are always on hand to answer any questions and provide guidance. So why wait? Sign up today and join the ranks of the world's greatest entrepreneurs. With DomainRooster, the sky's the limit! And remember, as the saying goes, "Successful people do what unsuccessful people are not willing to do." So don't be afraid to take that leap of faith - DomainRooster is here to help you reach for the stars. Caw on!