How Do I SCP with a Different Port?

3

This instructional explains switch information or directories the usage of SCP (Secure Copy Protocol) with a distinct port than the default 22 (SSH) port.

By default, the SCP command makes use of the port 22 (SSH). In case the faraway machine has configured the SSH carrier to run on a distinct port, you continue to can use SCP adopted via the -P flag to specify the port you want.

Note: For directions to switch the default ssh port at the faraway machine learn this phase.

Downloading Files Using SCP on a Different Port

To specify a distinct port than 22 when the usage of the SCP command, you want to put in force the -P flag as proven within the instance underneath, wherein the default port used to be modified to port 3940.

The syntax is beautiful easy as proven underneath.

scp -P Port> User>@IP/Host>:File> DestinationDirectory>

In the instance underneath, I display obtain the report named linuxint.report from the faraway host thru port 3940. The report is saved in the house listing of the faraway consumer named kali which I take advantage of to authenticate, that’s the default faraway location when no different is outlined.

At the top of the command, I specify the native listing wherein the report can be stored (Downloads).

scp -P 3940 kali@192.168.1.100:linuxhint.report ~/Downloads

As you’ll be able to see, the report switch used to be carried out effectively. The reason why explaining 0.0KB/S is that each one information for this instructional are empty.

Downloading Directories Using SCP on a Different Port

Downloading directories calls for an excessively equivalent syntax excluding for the -r flag which should be added moreover to the -P flag as proven within the instance underneath. The screenshot underneath presentations cpu the faraway listing named dir to the native house listing, all the way through port 3049.

scp -rP 3940 kali@192.168.1.100:dir ~/

How Do I SCP with a Different Port? How Do I SCP with a Different Port? 1631424364 359 How Do I SCP with a Different Port

As you’ll be able to see, the listing used to be downloaded recursively to the native house.

Uploading Files Using SCP with Different Port

Uploading information with SCP on a distinct port additionally calls for the -P flag. Remember the SCP command is very similar to the cp command. Therefore, when importing information, the report vacation spot listing should even be positioned on the finish of the command.

In the instance, underneath I add the linuxhint.report thru port 3940 to the faraway subdirectory named linuxhintdir, situated within the faraway house listing.

scp -P 3940 linuxhint.report kali@192.168.1.100:linuxhintdir

How Do I SCP with a Different Port? How Do I SCP with a Different Port? 1631424364 35 How Do I SCP with a Different Port

Uploading Directories Using SCP with Different Port

The instance underneath presentations add a listing as an alternative of a typical report. For this function, similar to when importing information, you most effective wish to upload the -r flag.

The following instance presentations add the listing named dir to the /tmp faraway listing thru port 3940.

scp -rP 3940 dir kali@192.168.1.100:/tmp

How Do I SCP with a Different Port? How Do I SCP with a Different Port? 1631424364 64 How Do I SCP with a Different Port

That’s all you want to understand to switch information the usage of SCP from or to a faraway instrument the usage of a distinct SSH port.

Change the Remote Default SSH Port from 22 to Other

To use SCP thru a distinct port, the opposite facet should have the port you need to make use of configured.

To trade the default SSH port, you want to edit the SSH configuration report. On maximum Linux distributions, you’ll be able to edit that report via working the command underneath.

sudo nano /and so on/ssh/sshd_config

Once opened, to find the road containing “Port 22” proven within the symbol underneath.

How Do I SCP with a Different Port? How Do I SCP with a Different Port? 1631424365 554 How Do I SCP with a Different Port

Change the quantity 22 for the port you need to make use of with SCP. In the screenshot underneath, you’ll be able to see I modified the default port to port 3940.

How Do I SCP with a Different Port? How Do I SCP with a Different Port? 1631424365 225 How Do I SCP with a Different Port

Once edited, press CTRL+X and Y to go out saving adjustments.

Then, restart the SSH carrier via working the command underneath.

sudo systemctl restart ssh

How Do I SCP with a Different Port? How Do I SCP with a Different Port? 1631424366 922 How Do I SCP with a Different Port

Now, you’ll have the ability to fetch or add information the usage of SCP at the port you outlined.

Conclusion

As you’ll be able to see, the usage of the SCP command thru other ports than 22 is beautiful simple to put in force. Yet, it is very important remind readers the SCP command is out of date and changed via more secure possible choices like rsync or sftp. Users should remember that even if the SCP command is according to the SSH protocol, the -P flag should be typed in higher case, opposite to the SSH port specification which is completed the usage of a lowercase -p.

Thank you for studying Linux Hint. I’m hoping this instructional used to be helpful. Keep following us for extra Linux guidelines and tutorials.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More