Skip to content Skip to sidebar Skip to footer

How to Upload Files to a Server Ssh

Secure Shell (SSH) is a mutual protocol used to admission or login to remote servers. The protocol is widely supported beyond Operating Systems. If you are Windows user, you may have heard and been using Putty, which is a SSH customer for Windows. Windows ten users tin use Open SSH customer that can exist installed via new feature installation. UNIX OSes normally come up with native SSH client support, so additional software installation is not needed.

The common control used to login to a server via ssh is equally follows:
-The server has a domain name (for e.g. server.com)

          local$ ssh user@server.com        

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

          local$ ssh user@120.thirteen.20.21        

Information technology is a recommended arroyo to add -5 (verbose) flag so that we will know what is currently happening during the login process.

          local$ ssh -5 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 control by calculation -p (port) flag. Allow's say the remote server enables SSH at port 202. Our SSH command at present becomes:

          local$ ssh -v -p 202 user@server.com  local$ ssh -v -p 202 user@120.13.twenty.21        

If public key infrastructure (PKI) is enabled for the SSH access to the remote server, nosotros and then demand to supply the individual fundamental to certify that nosotros are in the "client whitelist". Depending on how the private key was generated (east.g. using ssh-keygen, server creation wizard, etc) and its format, the boosted flag -i (identity file) should be added into the SSH control. Permit'southward assume the private key proper noun is server-priv-key.pem, the previous SSH command is now changed into:

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

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

Let'southward say we are uploading customer listing in a text format via FTP and the network is already tampered. Since the file is unencrypted when beingness uploaded, the attacker will immediately obtain the listing can use information technology for malign purpose.

Hence, it is recommended to use 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 way, an attacker in the network will not exist able to see the original file content because it is already encrypted when existence sent over the network.

Secure File Upload with scp

Unless the remote server is configured differently, it shall likewise let secure file upload using Secure Copy protocol (SCP) besides SSH admission. With scp nosotros can upload either files and folders to remote server.

Permit'due south say, we are using Mac Bone. The current directory is /Users/macuser/upload. We have a file named myfile.txt that we desire to upload to the remote server. The destination folder in the remote folder is /domicile/ubuntu/files.

SCP with standard SSH port

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

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

In the above commands, we supply -five flag to execute scp client in verbose mode. The ~ (tilde) sign refers to the user's 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). Later beingness uploaded to the remote server, the file path will be /abode/ubuntu/files/myfile.txt.

If nosotros need to provide the individual key, we should supply -i tag, similar with the SSH control. The scp command is at present changed into:

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

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

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

If we want to upload the content of mydir directory, we tin can provide * wildcard. By adding this wildcard, mydir directory volition 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:/abode/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        

SCP with non-standard SSH port

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

Allow's say the SSH port is 202. For single file upload, the SCP command at present becomes:

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

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

          mac@local ~$ scp -5 -P 202 -i /path/to/server-primal.pem -r ~/upload/mydir ubuntu@server.com:/home/ubuntu/files mac@local ~$ scp -5 -P 202 -i /path/to/server-central.pem -r /Users/macuser/upload/mydir ubuntu@120.13.20.21:/home/ubuntu/files        

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

          mac@local ~$ scp -v -P 202 -i /path/to/server-central.pem -r ~/upload/mydir/* ubuntu@server.com:/abode/ubuntu/files mac@local ~$ scp -v -P 202 -i /path/to/server-primal.pem -r /Users/macuser/upload/mydir/* ubuntu@120.13.20.21:/domicile/ubuntu/files        

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

grahamabightly.blogspot.com

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

Postar um comentário for "How to Upload Files to a Server Ssh"