- How to Download a File from a Server with SSH / SCP
- Downloading a File from Remote Server with SSH Secure Copy
- Downloading Files With SSH in Terminal
- Related
- Scp Command
- Sftp Command
- Security
- Get file from ssh linux
- How to download a file through an SSH server?
- 7 Answers 7
- How to SCP from Linux server to Windows client
- 9 Answers 9
- Get an admin command prompt
- Check available versions
- Install client
- Install server
- Start server and enable at boot
- Find your Windows IP address
- On your remote (Linux) machine, find your IP address.
- Create a public SSH key
- Copy public key from local (Windows) to remote (Linux) machine so you don’t have to type in a password all the time.
- Note that ssh-copy-id is not currently available on Windows.
- Do the same on your Linux machine (Note, ssh-copy-id does not work)
- Create a password on Windows if you don’t already have one
- Now you should be able to SSH or SCP from your Linux machine
How to Download a File from a Server with SSH / SCP
Users can securely download a file from any remote server with SSH by using the scp tool at the command line. Essentially this means you can have a file stored securely on a remote server and transfer it to local storage without having to expose that file to the outside world, because scp offers the same level of security and requires the same authentication that ssh does.
Securely downloading files with scp is aimed primarily at advanced users who are using ssh and the command line regularly in either macOS X, bsd, or linux. For those with adequate command line experience, using ssh and scp to download remote files is easy and, conveniently, after the file transfer has completed, the remote connection will end. This makes scp preferential to sftp for quick file downloads, though you could obviously use sftp if you wanted to as well.
Downloading a File from Remote Server with SSH Secure Copy
This assumes the remote server has ssh active, and if you’re able to ssh into the machine then it will have likely have scp active as well. If you don’t have a remote server to try this with, you can try it out between Mac OS X machines or with localhost if you enable ssh and Remote Login on the Mac beforehand.
The basic syntax to use scp (secure copy) for securely downloading remote files is as follows, replacing user, server, path, and target as appropriate:
scp user@server:/path/to/remotefile.zip /Local/Target/Destination
For example, to download a file to the local desktop named “filename.zip” located in the home directory of remote user “osxdaily” on server IP 192.168.0.45, the syntax would be as follows:
/Desktop/
Password:
filename.zip 100% 126 10.1KB/s 00:00
%
Assuming authentication is correct, the target file will immediately start to download to the target destination, offering a percentage completion, download speed, and elapsed transfer time as the file download proceeds.
As usual with the command line, it’s important to specify exact syntax.
If the file or path has a space in the name, you can use quotations or escaping on the path like so:
scp osxdaily@192.168.0.45:»/some remote directory/filename.zip»
scp can also be used to securely place a file on a remote server by adjusting the syntax as well, but we’re focusing on downloading a file rather than uploading files here.
If you’re new to ssh and testing this out yourself, and if you have never connected to the remote server before, you will be asked to confirm whether or not you wish to actually connect to the remote machine. This looks like so, and requires a ‘yes’ or ‘no’ answer before the download begins.
% scp osxdaily@192.168.0.4:filename.zip
/Desktop/
The authenticity of host ‘192.168.0.4 (192.168.0.4)’ can’t be established.
ECDSA key fingerprint is SHA256:31WalRuSLR83HALK83AKJSAkj972JJA878NJHAH3780.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.0.4’ (ECDSA) to the list of known hosts.
Password:
filename.zip 100% 126 0.1KB/s 00:00
%
Again, assuming the connection is approve and the login is successful, the remote file will download from the target server to the localhost.
You can also use scp to download multiple files from a remote server:
Using ssh for remote file downloads like this is most appropriate for secure transfers which require authentication. Sure you can also downloading files with curl or wget from remote servers, but files accessible with curl and wget tend to be accessible from the outside world as well, whereas ssh and scp requires authentication or a key, and uses 3DES encryption, making it considerably more secure.
Источник
Downloading Files With SSH in Terminal
Related
SSH, or secure shell, is a Unix shell used for secure communication between two networked computers. You may wish to securely download files from a remote system after establishing an SSH session. Secure file transfer within SSH is accomplished by two primary commands: scp and sftp, secure versions of the copy and file transfer commands.
To begin an SSH session, open a terminal application to gain access to a command line prompt. The precise method of SSH authentication may simply be a password or public-private key cryptography. See your system administrator for information about your particular system. Enter an SSH session using either the «ssh» or «slogin» command, passing the remote system name as input. Use the «-l» flag to specify a different user name on the remote system.
Scp Command
The «scp» command is a secure version of the Unix copy command «cp.» Once you establish an SSH session with the remote machine, locate the file you wish to copy. The «scp» command is a better option if you have only a few files to transfer. The «-p» flag preserved the file modification and access times.
To copy from the remote machine: scp -p remotemachine:/myfiles/myfile.txt x
To copy to the remote machine: scp -p myfile.txt remotemachine:/myfiles/
Sftp Command
File transfer protocol, or FTP, is the standard command for transferring files between computer systems. The «sftp» command is a secure version of «ftp» within a SSH session. To begin an «sftp» session:
To get files from the remote server, execute the «get» command at the sftp prompt:
sftp> get myfile.txt
To put files to the remote server, execute the «put» command: sftp> put myfile.txt
Security
Normal functions do not encrypt data that is sent over network connections. A password entered during a normal ftp session is sent in plain text. This can be especially problematic with critical systems. Using ssh, scp and sftp can prevent an intruder from easily gaining your password and keep both your system and the remote system safe.
Chris Daniels covers advances in nutrition and fitness online. Daniels has numerous certifications and degrees covering human health, nutritional requirements and sports performance. An avid cyclist, weightlifter and swimmer, Daniels has experienced the journey of fitness in the role of both an athlete and coach.
Источник
Get file from ssh linux
OpenSSH SSH/SecSH protocol suite (which comes pre-installed with OS X and available for download for most other *nix systems) includes the scp (secure copy) application which can be used to upload and download files from and to remote hosts.
Here are few examples of how to use it for:
1. Uploading a file from a local computer to a remote one:
scp /path/to/local/file username@hostname:/path/to/remote/file
This command can be used to upload a specific file to your account on the server:
scp -P 21098 /home/localuser/site/example.html cpanel_user@servername:/home/cpanel_user/public_html
Or this one, if the entire directory should be uploaded:
scp -P 21098 -r /home/localuser/site/ cpanel_user@servername:/home/cpanel_user/public_html
2. Downloading a file from a remote system to your computer:
scp username@hostname:/path/to/remote/file /path/to/local/file
This particular example can be used to download an error_log from public_html of a hosting account to your local computer:
scp -P 21098 cpanel_user@servername:/home/cpanel_user/public_html/error_log /home/localuser/logs/
NOTE: When one of the commands above is used, you will be asked to insert the password into your cPanel account (when you enter the password, it is automatically hidden for the security purposes).
1. Uploading a file from a local computer to a remote one:
scp /path/to/local/file username@hostname:/path/to/remote/file
This command can be used to upload a specific file to your account on the server:
2. Downloading a file from a remote system to your computer:
scp username@hostname:/path/to/remote/file /path/to/local/file
This particular example can be used to download an error_log from public_html of a hosting account to your local computer:
You can use PowerShell on other Windows versions as well following the next workarounds:
To use native Windows command line utilities, select the Start button > click on the Run… option. In the command line type in powershell and press Enter:
Here is an example of the command for downloading the file from the server to your computer:
Invoke-WebRequest http://domain.com/path-to-file.zip -UseBasicParsing -OutFile local.zip
http://domain.com/path-to-file.zip should be replaced with the URL to the file in question
local.zip should be replaced with the name you would like the downloaded file to be stored with. You may also specify a full path there. By default, it will be downloaded to C:\Users\your-windows-username directory:
The Invoke-WebRequest uses the HTTP protocol instead of SSH one. Its sole resemblance to scp is that the command line interface is being used as well.
This method has its disadvantages. First of all, the connection is not encrypted unless you have an SSL certificate and a specified https:// protocol in your URL. The file should be publicly accessible, which is not acceptable in some cases. Also, the file contents are stored in memory before being recorded to the disk, making this approach unsuitable for downloading large files.
2. Another workaround includes installing the Cygwin command line interface for Windows, which features the scp command. In order to use it, do the following:
- Download the cygwin installation file from here
- Install cygwin on your computer (do not forget to include openssh from the net bundle during installation process)
- Once installed, you will be able to run the scp command from the first part of the article using the Windows command line terminal (accessible via the Start button >Run… option > In the command line, type in cmd and press Enter).
Источник
How to download a file through an SSH server?
I have a server in USA (Linux box B), and my home PC (Linux box A), and I need download a file from website C,
The issue is, it is very slow to download a file direct from A, so I need download the file when I log in B, and sftp get the file from A.
Is there any way that I can download file and use B as proxy directly through only one line command?
7 Answers 7
(Strange situation, doesn’t something like the triangle inequality hold for internet routing?)
Anyway, try the following, on A, ssh into B with a -D argument,
which acts as a SOCKS5 proxy on 127.0.0.1:1080 , which can be used by anything supporting SOCKS5 proxied connections. Apparently, wget can do this, by using the environment variable
Note that sometimes curl is more handy (i.e. I’m not sure if wget can do hostname lookups via SOCKS5; but this is not one of your concerns I suppose); also Firefox is able to work completely through such a SOCKS5 proxy.
Edit I’ve just now noticed that you’re looking for a one-line solution. Well, how about
i.e. redirection the wget -fetched output to stdout , and redirecting the local output (from ssh running wget remotely) to a file.
This seems to work, the wget output is just a little confusing («saved to —«), you can get rid of it by adding -q to the wget call.
Источник
How to SCP from Linux server to Windows client
I’m SSHing into a Linux machine using PuTTY and trying to copy a file down somewhere (anywhere) to my local machine. I figure SCP is the best candidate for the job but don’t really care, so long as the solution works!
I cd to the directory containing the file I want ( app.war ) and type the following:
I’ve tried both to no avail:
It got me thinking that perhaps SCP is a client/server tool and requires a client on my Windows machine, which isn’t there.
Am I just using the wrong syntax? Or am I way off-base? If so, what options do I have? Thanks in advance!
9 Answers 9
in order for you to copy files back to your Windows you need SSH daemon/service to be running on your Windows, it’s much easier to use this tool instead, it has an ability to import sessions from Putty, very plain forward client you’ll love it!
You are correct. SSHD is the SSH server services that runs on the host. It accepts connections from SSH clients (like PuTTy), SCP clients, and SFTP clients.
You can download pscp from the same website where PuTTY is hosted.
From the windows machine, you would execute a command similar to
pscp.exe someuser@somehost.com:/path/to/app.war c:\tmp
Get an admin command prompt
Check available versions
Install client
Install server
Start server and enable at boot
Find your Windows IP address
On your remote (Linux) machine, find your IP address.
Create a public SSH key
Copy public key from local (Windows) to remote (Linux) machine so you don’t have to type in a password all the time.
Note that ssh-copy-id is not currently available on Windows.
Do the same on your Linux machine (Note, ssh-copy-id does not work)
The method above did not work for me, so I ended up manually SCPing the public key over and pasting it into the C:/Users/YOU/.ssh/authorized_keys file.
That still did not work, so I had to modify the sshd_config file.
Open Notepad as Administrator
Add the following lines:
Create a password on Windows if you don’t already have one
— Note, you can still disable the Windows login screen by a) Setting the ‘Require sign-in’ option to never and b) Using the ‘netplwiz’ command and unticking the ‘Users must enter password. ‘ checkbox.
Now you should be able to SSH or SCP from your Linux machine
You can do this by using the Linux Ubuntu subsystem for Windows (you need to enable this as a Windows feature). Then you can use a Linux terminal client that runs on Windows by getting it from the Microsoft Store (e.g. Ubuntu 16.04 LTS). Then, if you have ssh security set up to remote into your Linux machine, you can scp from your local Windows Ubuntu terminal (when logged in as the username that you set for your Linux instance) something like this:
/ . enter RSA passphrase
The remote file will be copied into your local Ubuntu filesystem used by Windows e.g.
To SCP a file to a Windows machine, you need an SSH/SCP server on the Windows.
There’s no SSH/SCP support in Windows by default. You can install Microsoft build of OpenSSH for Windows (Releases and Downloads). It’s available as optional feature on Windows 10 version 1803 and newer. It can also be manually installed on older versions of Windows.
Though as you SSH into the Linux server from the Windows machine, you actually can download a file from the Linux server to the Windows server, instead of trying to upload the file from the Linux server to Windows server.
In you have an SSH access from Windows to Linux, you have an SCP access too (or even better an SFTP access).
Use any SCP/SFTP client available.
Another alternative is PuTTY toolset, which includes the pscp command-line tool with a syntax similar to the OpenSSH scp command. Also the latest versions of Windows 10 comes with OpenSSH scp built-in and it can be installed on older versions too.
Источник