$ sudo chown root:root \/home\/remoteuser<\/code><\/pre>\n\n\n\nNow, create new subdirectories within web server root or even the user home directory which used for file transfer. Usually when you set up SFTP User accounts, you intend to use them to transfer website files. We will be making that assumption for the rest of this guide. Feel free to set up for whichever situation you working with.<\/p>\n\n\n\n
Let’s proceed. Grant the user ownership rights to the subdirectories.<\/p>\n\n\n\n
$ sudo chown -R remoteuser:remoteuser \/var\/www\/thewebsite.com\/websitefiles<\/code><\/pre>\n\n\n\nGive read and write permissions to all files within the desired directory.<\/p>\n\n\n\n
$ sudo chmod -R 755 \/var\/www\/thewebsite.com\/websitefiles<\/code><\/pre>\n\n\n\nConfigure SFTP Support on Your Ubuntu 22.04 System<\/h2>\n\n\n\n We can enable SFTP by making a few changes in the main SSH configuration file. Using an editor of your choice, open the file \/etc\/ssh\/sshd_config<\/code>. In this guide we will be using nano<\/strong>.<\/p>\n\n\n\n$ sudo nano \/etc\/ssh\/sshd_config<\/code><\/pre>\n\n\n\nAdd the following lines to the end of the file. Remember to replace sftp_users<\/code> with your actual sftp group.<\/p>\n\n\n\nMatch Group sftp_users\nChrootDirectory %h\nPasswordAuthentication yes\nAllowTcpForwarding no\nX11Forwarding no\nForceCommand internal-sftp<\/code><\/pre>\n\n\n\nIf your SFTP user has a home directory in a custom location such as the example we gave above you will need to add these lines after the above code for each user that has custom home directories.<\/p>\n\n\n\n
Match User remoteuser\nChrootDirectory \/var\/www\/thewebsite.com\/websitefiles<\/code><\/pre>\n\n\n\nThis is a high level overview of what the above directives mean.<\/p>\n\n\n\n
Match Group sftp_users<\/strong>: This means the next directied should apply to the user group sftp_users.<\/li>ChrootDirectory %h<\/strong>: This restricts access to directories within the user’s home directory.<\/li>PasswordAuthentication yes<\/strong>: Enable password authentication.<\/li>AllowTcpForwarding no<\/strong>: Disable TCP forwarding.<\/li>X11Forwarding no<\/strong>: Disallow Graphical User interface displays.<\/li>ForceCommand internal-sftp<\/strong>: Enable SFTP only while restricting shell access.<\/li><\/ul>\n\n\n\nLook for the following line in the file and make sure it is uncommented. By default, it is usually disabled.<\/p>\n\n\n\n
# override default of no subsystems\nSubsystem sftp \/usr\/lib\/openssh\/sftp-server<\/code><\/pre>\n\n\n\nSave and close the file.<\/p>\n\n\n\n
Now we can restart the SSH service for changes to take effect.<\/p>\n\n\n\n
$ sudo systemctl restart sshd<\/code><\/pre>\n\n\n\nConfirm Login to SFTP<\/h2>\n\n\n\n Open a new terminal window and log in with sftp using a valid user account and password.<\/p>\n\n\n\n
$ sftp remoteuser@SERVER-IP<\/code><\/pre>\n\n\n\nYou can try creating a new directory within the subdirectory to test user permissions.<\/p>\n\n\n\n
$ mkdir test<\/code><\/pre>\n\n\n\nConfirm creation of the new directory:<\/p>\n\n\n\n
$ ls\n\nOutput\n\n> ls\ntest\n><\/code><\/pre>\n\n\n\nIdeally you will want to use SFTP client applications to connect to remote systems. FileZilla and Cyberduck are the most popular SFTP client applications available for Windows, Mac, and Linux desktop systems.<\/p>\n\n\n\n
Conclusion<\/h2>\n\n\n\n If you have gotten this far, congratulations. You have successfully set up SFTP User accounts on Ubuntu 22.04 Linux systems. You went further to restrict their use on the system and even tested the connectivity using a Linux terminal session. With the steps highlighted in this guide you can create as many SFTP users as you see fit.<\/p>\n","protected":false},"excerpt":{"rendered":"
In this guide, we will show you how to set up SFTP User accounts on Ubuntu 22.04 Linux systems. The steps shown here will also restrict the users to their…<\/p>\n","protected":false},"author":1,"featured_media":12743,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,16,18],"tags":[121,183,193,354,433,573,591,598],"yoast_head":"\n
How to Set up SFTP User Accounts on Ubuntu 22.04<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n \n \n\t \n\t \n\t \n