<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://dikapediav2.com/wiki/index.php?action=history&amp;feed=atom&amp;title=SFTP</id>
	<title>SFTP - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://dikapediav2.com/wiki/index.php?action=history&amp;feed=atom&amp;title=SFTP"/>
	<link rel="alternate" type="text/html" href="https://dikapediav2.com/wiki/index.php?title=SFTP&amp;action=history"/>
	<updated>2026-05-15T09:11:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://dikapediav2.com/wiki/index.php?title=SFTP&amp;diff=167&amp;oldid=prev</id>
		<title>Ardika Sulistija: Created page with &quot;  &lt;B&gt;SFTP&lt;/B&gt; - Secure File Transfer Protocol   ----   To open an SFTP connection to a remote system, use the sftp command followed by the remote server username and the IP address or domain name:  sftp remote_username@server_ip_or_hostname   Once connected, you will be presented with the sftp prompt, and you can start interacting with the remote machine:  # To &#039;get&#039; Download file usin SFTP from remote server to your local machine.  sftp&gt; get [file]    # To &#039;put Upload f...&quot;</title>
		<link rel="alternate" type="text/html" href="https://dikapediav2.com/wiki/index.php?title=SFTP&amp;diff=167&amp;oldid=prev"/>
		<updated>2024-09-11T14:25:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;  &amp;lt;B&amp;gt;SFTP&amp;lt;/B&amp;gt; - Secure File Transfer Protocol   ----   To open an SFTP connection to a remote system, use the sftp command followed by the remote server username and the IP address or domain name:  sftp remote_username@server_ip_or_hostname   Once connected, you will be presented with the sftp prompt, and you can start interacting with the remote machine:  # To &amp;#039;get&amp;#039; Download file usin SFTP from remote server to your local machine.  sftp&amp;gt; get [file]    # To &amp;#039;put Upload f...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;B&amp;gt;SFTP&amp;lt;/B&amp;gt; - Secure File Transfer Protocol &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To open an SFTP connection to a remote system, use the sftp command followed by the remote server username and the IP address or domain name:&lt;br /&gt;
 sftp remote_username@server_ip_or_hostname&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once connected, you will be presented with the sftp prompt, and you can start interacting with the remote machine:&lt;br /&gt;
 # To &amp;#039;get&amp;#039; Download file usin SFTP from remote server to your local machine.&lt;br /&gt;
 sftp&amp;gt; get [file]&lt;br /&gt;
 &lt;br /&gt;
 # To &amp;#039;put Upload file using SFTP from local machine to remote server.&lt;br /&gt;
 sftp&amp;gt; put [file]&lt;br /&gt;
 &lt;br /&gt;
 # Other useful commands:&lt;br /&gt;
 sftp&amp;gt; help&lt;br /&gt;
 sftp&amp;gt; pwd&lt;br /&gt;
 sftp&amp;gt; ls&lt;br /&gt;
 sftp&amp;gt; cd /tmp&lt;br /&gt;
 sftp&amp;gt; cd lpwd                 # To print local working directory&lt;br /&gt;
 sftp&amp;gt; mkdir directory_name    # Create a new directory on remote server&lt;br /&gt;
 sftp&amp;gt; rename [file]           # Rename a file on remote server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Detailed steps of restricted SFTP-only access to a single directory====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 There are many similar cases that customers (usually Wordpress users ) want to restrict some of their users only have the access to a single directory. I would like to put them together in case some of our customers ask for the detail steps rather than refer to the third-party website:&lt;br /&gt;
&lt;br /&gt;
1. Create a New Group&lt;br /&gt;
&lt;br /&gt;
Create a group called sftpusers. Only users who belong to this group will be automatically restricted to the SFTP chroot environment on this system.&lt;br /&gt;
&lt;br /&gt;
$ sudo su&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# groupadd sftpusers&lt;br /&gt;
&lt;br /&gt;
2. Create Users (or Modify Existing User)&lt;br /&gt;
&lt;br /&gt;
Let us say you want to create an user guestuser who should be allowed only to perform SFTP in a chroot environment, and should not be allowed to perform SSH.&lt;br /&gt;
&lt;br /&gt;
The following command creates guestuser, assigns this user to sftpusers group, make /incoming as the home directory, set /sbin/nologin as shell (which will not allow the user to ssh and get shell access).&lt;br /&gt;
&lt;br /&gt;
# useradd -g sftpusers -d /incoming -s /sbin/nologin guestuser&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# passwd guestuser (eg: 12345678 )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Verify that the user got created properly.&lt;br /&gt;
&lt;br /&gt;
# grep guestuser /etc/passwd&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
guestuser:x:500:500::/incoming:/sbin/nologin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to modify an existing user and make him an sftp user only and put him in the chroot sftp jail, do the following:&lt;br /&gt;
&lt;br /&gt;
# usermod -g sftpusers -d /incoming -s /sbin/nologin &amp;lt;current user name&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Setup sftp-server Subsystem in sshd_config&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should instruct sshd to use the internal-sftp for sftp (instead of the default sftp-server). Modify the the /etc/ssh/sshd_config file and comment out the following line:&lt;br /&gt;
&lt;br /&gt;
#Subsystem       sftp    /usr/libexec/openssh/sftp-server&lt;br /&gt;
&lt;br /&gt;
Next, add the following line to the /etc/ssh/sshd_config file&lt;br /&gt;
&lt;br /&gt;
#Subsystem sftp /usr/libexec/openssh/sftp-server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Subsystem sftp internal-sftp&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Specify Chroot Directory for a Group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You want to put only certain users (i.e users who belongs to sftpusers group) in the chroot jail environment. Add the following lines at the end of /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Match Group sftpusers&lt;br /&gt;
&lt;br /&gt;
    ChrootDirectory /sftp/%u&lt;br /&gt;
&lt;br /&gt;
    ForceCommand internal-sftp&lt;br /&gt;
&lt;br /&gt;
    PasswordAuthentication yes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So this configuration will allow this current user “guestuser” sftp to the instance with password instead of using the same ssh key pair.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create sftp Home Directory&lt;br /&gt;
&lt;br /&gt;
Since we’ve specified /sftp as ChrootDirectory above, create this directory (which iw equivalent of your typical /home directory).&lt;br /&gt;
&lt;br /&gt;
# mkdir /sftp&lt;br /&gt;
&lt;br /&gt;
Now, under /sftp, create the individual directories for the users who are part of the sftpusers group. i.e the users who will be allowed only to perform sftp and will be in chroot environment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# mkdir /sftp/guestuser&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, /sftp/guestuser is equivalent to / for the guestuser. When guestuser sftp to the system, and performs “cd /”, they’ll be seeing only the content of the directories under “/sftp/guestuser” (and not the real / of the system). This is the power of the chroot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, under this directory /sftp/guestuser, create any subdirectory that you like user to see. For example, create a incoming directory where users can sftp their files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# mkdir /sftp/guestuser/incoming&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Setup Appropriate Permission&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For chroot to work properly, you need to make sure appropriate permissions are setup properly on the directory you just created above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Set the owenership to the user, and group to the sftpusers group as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# chown guestuser:sftpusers /sftp/guestuser/incoming&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The permission will look like the following for the incoming directory.&lt;br /&gt;
&lt;br /&gt;
# ls -ld /sftp/guestuser/incoming&lt;br /&gt;
&lt;br /&gt;
drwxr-xr-x 2 guestuser sftpusers 4096 Dec 28 23:49 /sftp/guestuser/incoming&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The permission will look like the following for the /sftp/guestuser directory&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ls -ld /sftp/guestuser&lt;br /&gt;
&lt;br /&gt;
drwxr-xr-x 3 root root 4096 Dec 28 23:49 /sftp/guestuser&lt;br /&gt;
&lt;br /&gt;
# ls -ld /sftp&lt;br /&gt;
&lt;br /&gt;
drwxr-xr-x 3 root root 4096 Dec 28 23:49 /sftp&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***********************************************************************************************************************&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For WordPress user:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Mount-&amp;gt; the source directory /sftp/guestuser/ to the target directory /www/var/html/mysite&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# chown guestuser:sftpusers /www/var/html/mysite&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the mount:&lt;br /&gt;
&lt;br /&gt;
#mount -l&lt;br /&gt;
&lt;br /&gt;
#mount -R /var/www/html/mysite /sftp/guestuser/incoming/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Restart sshd and Test Chroot SFTP&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart sshd:&lt;br /&gt;
&lt;br /&gt;
# service sshd restart&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Test chroot sftp environment. As you see below, when gusetuser does sftp, and does “cd /”, they’ll only see incoming directory that mounted on /var/www/html/mysite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the instance:&lt;br /&gt;
&lt;br /&gt;
$ sftp guestuser@&amp;lt;IP address&amp;gt;&lt;br /&gt;
&lt;br /&gt;
guestuser@&amp;lt;IP address&amp;gt;&amp;#039;s password: ********&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer:&lt;br /&gt;
&lt;br /&gt;
http://www.thegeekstuff.com/2012/03/chroot-sftp-setup/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[+][https://linuxize.com/post/how-to-use-linux-sftp-command-to-transfer-files/ Click here for more info/examples]&lt;/div&gt;</summary>
		<author><name>Ardika Sulistija</name></author>
	</entry>
</feed>