The internet is full of endless possibilities aimed to make the lives of website owners as seamless as possible.
Of these possibilities, some work comparably well than, and after a few trials, we find ourselves stuck with the newer and improved solutions.
One such solution is the one involving copying files from one server to another.
If you’d like to copy your files from an old web server on to a newer server online, you could use SSH.
Thanks to SSH, you no longer have to download your entire website to your local computer, and you might not have to use the third party file transfer tools like FTP to log into your web host’s servers then transfer your files to another server.
Thanks to SSH, you don’t need to use your computer as the middleman in the transfer/ copying of files from one server to another.
You might also like SSH because you will not have to download any files before transfer.
Table of Contents
What is SSH?
SSH or Secure Shell refers to a secure network protocol that is used in the operation of network services most securely.
For this secure network operation, there should be a secure channel that is established over a somewhat unsecured network.
How different is the use of SSH from the use of traditional FTP apps?
Well, unlike your third-party apps used as FTPs, SSH runs or is operated through a command line.
The command line could be a Terminal or even the Command Prompt present in Windows.
The command line could be used in either Mac or Linux computers.
Unfortunately, if you are using a pre-10 version of Windows, you need another third party app for you to use the SSH command line.
The reason for the third party app comes from the fact that the use of SSH wasn’t active/ native to the Windows OS before Windows 10.
If your computer is running on a native Windows operating system, you’ll need an app called Putty to use the SSH command.
If, on the other hand, you are using a Linux or a Mac computer, you will not need a third party app because SSH is one of the native features of these computers and SSH is available straight from the box.
There is also the fact that most web hosting servers run on Linux which means that unless your servers run on a Windows equivalent, the IIS/ Internet Information Service, then SSH will be available and you will not need Putty or any other third party apps.
The SSH command contains three unique parts: SSH, User, and Host.
For file transfer, the SSH key command will instruct the system of your intention to open the encrypted Secure Shell Connection while the User bit of the command is the account you wish to access.
This means that if you wish to access your root user, you are accessing it as the system administrator with all the rights needed to modify the system.
The Host represents the computer that you wish to access; it could be an IP address or a domain name.
After hitting enter, you’re prompted to provide the password for the account requested.
Note that while nothing appears on the screen, the password will be transmitted.
A terminal window opens if you enter the correct password.
Security of SSH
As mentioned above, SSH file transfer between server is secure thanks to heavy encryption.
The high level of security comes for the three encryption technologies by SSH: Hashing, Asymmetrical encryption, and symmetrical encryption.
These encryptions use the client-server model to accept the authentication of two remote server systems and the encryption of the data between the servers. SSH run on TCP port 22 (by default).
The host server listens on the port 22 for any incoming connections then organizes secure connection between the servers by authenticating client server.
If verification is successful, it opens the correct shell environment.
The client will be required to start an SSH connection through the initiation of a TCP handshake with the server.
This process ensures secured (symmetric) connection, and it verifies whether or not the identity that is displayed by the server matches the previous records, then it presents the necessary credentials of the user to authenticate the connection.
For the establishment of the connection, the two systems should first agree on the preferred encryptions standard for the protection of future connections then the users have to authenticate themselves.
What is SCP?
When copying files using the SSH Command, there is something else you need to be aware of: the SCP or Secure Copy Protocol.
As long as you are copying files using SSH, you will require SCP. SCP refers to the method through which files are securely transferred.
The use of SCP ensures the transfer of complete folders between the selected computers with SCP, anyone (client) can upload or send files to a remote server securely, or they could request files without worrying about a security issue.
SCP is based on the SSH protocol, and it could be used for file transfer across remote servers.
How to transfer files across servers with the SSH command
First, we have to go through the process of connecting to the remote Mac or Linux server using a local Windows computer with Putty installed.
To access the remote server, you must have a virtual server (highly recommended).
Your virtual server should have a newly-built template which will ensure that accidental deletions can be recovered and that you can rebuild your server if you delete information accidentally.
The virtual server ensures that you have everything you need if things go south.
Now, to connect to the remote server, you will need the Secure Shell/ SSH command. The basic command used is ssh user@serverip.
This is the command that will connect you to the server with the IP address’ server IP and the user’s username.
Alternatively, you could connect to the remote server using the SSH server IP which will make the secure shell think that you are connecting to the server using the same user name that you are logged into.
For seamless copying of files, follow these steps:
Log into the remote server using the web console then access the control panel.
Confirm that SSH is enabled on the two ends.
The SSH access, in its default setting, is disabled and you have to activate the access.
Once activated, you need to record your assigned SSH username then enter and re-enter your password to complete your SSH account activation.
Note that while you could change the password later, the instructions you receive might be server-specific.
Next, record your SSH connection details for future use.
You should also keep a record of your server’s host key.
Establishing the server connection
If using Windows, activate Putty the establish your connection to the selected remote server.
To initiate the connection, you should enter the necessary information in the Host Name Field using the configuration window.
Keep in mind that if the connection to the server is happening for the first time, Putty will give you a security alert.
You should not, however, see the security alert for subsequent connections – should you receive a security alert in a subsequent connection, then you could be dealing with an attack called the Man-in-the-Middle attack.
Otherwise, click Yes and continue.
Putty will give you a terminal window. To access the window, enter your login credentials then hit Enter.
Once you’re logged in successfully, the terminal window will give you an access line/ command line on the server.
Type in your commands for limited access to the server.
Go to your destination folder located on the remote server using Putty then confirm the contents of the selected folder to ensure that you don’t have files or folders with the same name as the folders/ files you intend to transfer.
In case of files/folders with similar names, you should consider moving them to another folder, delete or rename them.
Having located the files, you wish to transfer, use the SCP to transfer those files from one server onto the next.
Ensure that your Secure Copy Syntax is in the correct format (scp [switch] [source content location] [destination content location].
SCP is required for the activation of the transfer function. Switch is the optional function, and you don’t need it to transfer a single file or even multiple files in one directory, destined for one folder.
You’ll need the Switch function, however, when transferring entire folders.
The content Location syntax will vary depending on its location – on the server you’ve logged into or on the second remote server you aren’t logged into.
Generally, the syntax required when copying a directory between remote servers is
scp -r firstname.lastname@example.org:/var/www/ /var/www/dir.
Once you enter the syntax information, the system will prompt you to enter the password for the other remote server.
Click enter once you enter your credentials.
The file transfer should begin after entering the right password for your second remote server.
Once the transfer begins, you can close your terminal window without worrying about the disruption of the process between the two servers.
There you have it – seamless and secure copying of files between two servers using SSH.