Upload Folder to Server With Ssh Terminal

Secure Beat (SSH) is a common protocol used to access or login to remote servers. The protocol is widely supported across Operating Systems. If you are Windows user, you may have heard and been using Putty, which is a SSH customer for Windows. Windows x users can use Open SSH client that tin can be installed via new feature installation. UNIX OSes usually come with native SSH customer back up, so additional software installation is not needed.

The common command used to login to a server via ssh is as follows:
-The server has a domain name (for e.chiliad. server.com)

          local$ ssh user@server.com        

-The server but has IP accost or an IP address that maps to a domain proper name (for e.one thousand. 120.13.xx.21 -> server.com)

          local$ ssh user@120.thirteen.20.21        

Information technology is a recommended approach to add together -5 (verbose) flag then that we will know what is currently happening during the login procedure.

          local$ ssh -v user@server.com local$ ssh -v user@120.13.20.21        

The standard port for SSH is port 22. If the remote server uses different port for SSH, we need to specify this in the SSH command by adding -p (port) flag. Allow's say the remote server enables SSH at port 202. Our SSH command now becomes:

          local$ ssh -5 -p 202 user@server.com  local$ ssh -v -p 202 user@120.xiii.xx.21        

If public key infrastructure (PKI) is enabled for the SSH access to the remote server, we then need to supply the individual cardinal to certify that nosotros are in the "client whitelist". Depending on how the private key was generated (e.g. using ssh-keygen, server cosmos magician, etc) and its format, the additional flag -i (identity file) should exist added into the SSH command. Let's presume the private fundamental name is server-priv-key.pem, the previous SSH command is now changed into:

          local$ ssh -v -p 202 -i /path/to/server-priv-primal.pem user@server.com local$ ssh -five -p 202 -i /path/to/server-priv-primal.pem user@120.13.twenty.21        

SSH cannot exist used to transfer or upload files from the current host to the remote server. Traditionally, we may opt to FTP. All the same, FTP is not a secure protocol. The file will be uploaded unencrypted thus making it more vulnerable to network attack. An adversary (assaulter) may capture the FTP traffic and immediately decode the content of the file(s) being uploaded.

Let's say we are uploading customer list in a text format via FTP and the network is already tampered. Since the file is unencrypted when being uploaded, the attacker will immediately obtain the list can use it for malign purpose.

Hence, information technology is recommended to employ secure protocol like SCP to upload the file to the remote server. This protocol volition encrypt the file before getting uploaded to the remote server. This style, an attacker in the network volition not be able to see the original file content considering information technology is already encrypted when being sent over the network.

Secure File Upload with scp

Unless the remote server is configured differently, it shall besides let secure file upload using Secure Re-create protocol (SCP) besides SSH access. With scp we can upload either files and folders to remote server.

Let's say, we are using Mac Os. The electric current directory is /Users/macuser/upload. We have a file named myfile.txt that we desire to upload to the remote server. The destination binder in the remote folder is /home/ubuntu/files.

SCP with standard SSH port

If the SSH connection to remote server is using the standard port (port 22), we and so upload the file using this command:

          mac@local ~$ scp -v ~/upload/myfile.txt ubuntu@server.com:/home/ubuntu/files mac@local ~$ scp -v /Users/macuser/upload/myfile.txt ubuntu@120.thirteen.20.21:/home/ubuntu/files        

In the above commands, we supply -v flag to execute scp customer in verbose mode. The ~ (tilde) sign refers to the user'southward home directory that is defaulted to /Users/macuser (given that the user account is macuser) in Mac OS or /home/ubuntu (given that the user business relationship is ubuntu). After existence uploaded to the remote server, the file path will exist /habitation/ubuntu/files/myfile.txt.

If nosotros demand to provide the private fundamental, we should supply -i tag, similar with the SSH command. The scp command is now inverse into:

          mac@local ~$ scp -v -i /path/to/server-key.pem  ~/upload/myfile.txt ubuntu@server.com:/habitation/ubuntu/files mac@local ~$ scp -v -i /path/to/server-key.pem /Users/macuser/upload/myfile.txt ubuntu@120.xiii.20.21:/dwelling/ubuntu/files        

What if we want to upload a directory? Now consider a directory named mydir located in /Users/macuser. To upload this directory, we should supply the -r (recursive) tag. If we want the directory to be uploaded into /home/ubuntu/files/mydir, we then invoke the scp control as follows:

          mac@local ~$ scp -v -i /path/to/server-cardinal.pem -r ~/upload/mydir ubuntu@server.com:/domicile/ubuntu/files mac@local ~$ scp -v -i /path/to/server-key.pem -r /Users/macuser/upload/mydir ubuntu@120.13.twenty.21:/home/ubuntu/files        

If we want to upload the content of mydir directory, we can provide * wildcard. By calculation this wildcard, mydir directory will not be created in the remote server and instead the directory content will be uploaded to the remote directory destination.

          mac@local ~$ scp -5 -i /path/to/server-key.pem -r ~/upload/mydir/* ubuntu@server.com:/habitation/ubuntu/files mac@local ~$ scp -v -i /path/to/server-key.pem -r /Users/macuser/upload/mydir/* ubuntu@120.13.20.21:/dwelling house/ubuntu/files        

SCP with non-standard SSH port

When using SSH to connect to remote server, we will use -p flag to specify the SSH port. This is different with SCP. Instead of -p flag (lowercase p), nosotros need to supply -P flag (capital P) to specify the SSH port.

Let'due south say the SSH port is 202. For single file upload, the SCP command now becomes:

          mac@local ~$ scp -v -P 202 -i /path/to/server-key.pem  ~/upload/myfile.txt ubuntu@server.com:/home/ubuntu/files mac@local ~$ scp -v -P 202 -i /path/to/server-key.pem /Users/macuser/upload/myfile.txt ubuntu@120.13.20.21:/home/ubuntu/files        

For directory upload with directory creation, the SCP control is now changed into:

          mac@local ~$ scp -v -P 202 -i /path/to/server-fundamental.pem -r ~/upload/mydir ubuntu@server.com:/domicile/ubuntu/files mac@local ~$ scp -five -P 202 -i /path/to/server-fundamental.pem -r /Users/macuser/upload/mydir ubuntu@120.13.xx.21:/home/ubuntu/files        

And finally, for directory content upload, we will have the post-obit SCP command:

          mac@local ~$ scp -5 -P 202 -i /path/to/server-central.pem -r ~/upload/mydir/* ubuntu@server.com:/home/ubuntu/files mac@local ~$ scp -5 -P 202 -i /path/to/server-key.pem -r /Users/macuser/upload/mydir/* ubuntu@120.xiii.twenty.21:/domicile/ubuntu/files        

How is your experience using SCP so far? Just share your feel in the comment section.

harpersincen.blogspot.com

Source: https://tech.amikelive.com/node-651/using-scp-to-securely-upload-files-and-directories-to-remote-server/

0 Response to "Upload Folder to Server With Ssh Terminal"

Enviar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel