News
New LLM GPT PHI-4 from Microsoft available now!
JT
January 31 2025
Updated January 31 2025

How do I set up and use SFTP?

Linux Networks Windows

The question often arises, when setting up and operating various OS distributions, how to transfer files securely over the network? Let's say at once that there are a lot of protocols, but in our opinion, one of the most effective and convenient is SFTP!

Enough, convenient to use, as it offers an interactive shell to work with the file system and a set of basic commands!

What is SFTP?

SFTP, or Secure File Transfer Protocol, is a protocol used for encrypted data transfer that supports user authentication and is often pre-installed on many distributions. Since it is technically implemented in SSH service, the configuration of users and authentication methods is absolutely identical.

Recall that sshd uses Linux PAM modules to authenticate users, and also has its own agent to obtain and verify encryption keys.

Once you have exchanged public encryption keys or created a new user with a password, you should proceed to install the service if you have not already installed it.

Installing and managing files via SFTP

Usually it is enough to install openssh-server, as the other packages are downloaded by dependencies:

apt install openssh-server

For Windows it will be similar, you can find the file on the developers website, but it is better to use trusted repositories and install via the command:

Get-WindowsCapability -Online | Where-Object Name -like ‘OpenSSH.Server*’ | Add-WindowsCapability -Online

After that, to connect to the SFTP server you need to write a command with the syntax:

sftp -P port_number user_name@hostname
sftp-connect
Screenshot № 1 — SFTP connect

Let's look through the possible functionality of the utility and consider the implementation of functions on a practical example:

Basic command
Screenshot № 2 — Basic command

First of all, we need to see what directories we are in on the remote OS and locally. Unfortunately, SFTP does not support the ability to execute more than one command at a time, so they will be executed separately:

pwd
lpwd
PWD
Screenshot № 3 — PWD

We can then view the list of files on the remote and local device:

ls
lls
List of files
Screenshot № 4 — List of files

For example, we need to transfer the file t.txt to the remote device, for this we will write:

put -R local-path remote-path
Upload files
Screenshot № 5 — Upload files

The same approach can be used for commands, then it will be necessary to add the -R option to the beginning for recursive copying of data. Downloading files from a remote device can be done with the same simple command:

get -R remote-path local-path
Download files
Screenshot № 6 — Download files

Since sessions are interactive shells, you may need to use the local OS for a while without leaving the session:

!command-in-the-shell
Shell code
Screenshot № 7 — Shell code

If we want to open a full-fledged shell, we use the command:

!command-in-the-shell
Shell
Screenshot № 8 — Shell

And to exit from it q or exit. This will then open cmd for Windows and the standard specified user shell for Linux. This set of basic commands will allow secure file transfers between devices. The setup is quite simple, as the protocol and server part are already implemented in the boot package and loaded by a dependency to the machine.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.