I would like to know how to set up root, sudo, sftp-only user accounts which won't be required public key authentication at log in. I would also like to know how to set up sftp-only users' home directories where they can't access upper level other directories.
Ubuntu – How to setup a restricted SFTP server on Ubuntu
opensshserversftp
Best Answer
The best resource to help you begin setting up an ssh service on a Host machine using Ubuntu is OpenSSH Server. This will allow you to use SSH File Transfer Protocol (also Secure File Transfer Protocol, or SFTP) to access, transfer, and manage files over SSH from a Client machine.
Overview of Solution
OpenSSH server
on a Host machine and a user can then usessh
to connect from Client to Host's server using only a username and password. Note, however, that public key authentication is recommended,Install and configure your OpenSSH Server on Host
To install an OpenSSH server on Host:
Give your Host a Static IP address so you can reliably connect to it:
To configure your OpenSSH server, "first, make a backup of your sshd_config file by copying it to your home directory, or by making a read-only copy in /etc/ssh by doing:"
"Once you've backed up your
sshd_config
file, you can make changes with any text editor, for example:"You must restart your ssh service on Host for these changes to take effect
Consider the Following Security Measures
PermitRootLogin without-password
; addPermitRootLogin no
to Host's/etc/ssh/sshd_config
Port 22
; addPort <new-port-number>
to Host's/etc/ssh/sshd_config
ListenAddress 192.168.0.10
AllowUsers <username>@<IP_address_1> <username>@<IP_address_2>
orAllowUsers <username>@111.222.333.*
to Host's/etc/ssh/sshd_config
~/.ssh/id_rsa.pub
from each Client as a new line of Host's~/.ssh/authorized_keys
. Then addPasswordAuthentication no
to to Host's/etc/ssh/sshd_config
sudo apt-get install ufw && sudo ufw limit OpenSSH
If you feel you must, Enable
PasswordAuthentication
in yoursshd_config
fileFind the line with the phrase
PasswordAuthentication
and make it read:Save your new
sshd_config
file and then restart Host'sssh
service:If you need access from anywhere over the internet, Setup Port Forwarding on your local router to direct traffic to your OpenSSH server
Note the port Host's
ssh
service listens to in thesshd_config
file and setup your router to forward TCP/UDP traffic aimed at this port to the IP address of your OpenSSH server.192.168.1.1
in order to login to your router and setup port forwarding. See Configure OpenSSH server and router to accept SSH connection over internet?Connect to Host and login via command-line or terminal
To open an SFTP shell terminal as
<username>
on Host, open a Terminal on Client and enter the following command, replacing123.123.1.23
with Host's IP address:If you changed the port number Host's OpenSSH server listens to, do:
To open an SSH shell terminal as
<username>
on Host, open a Terminal on Client and enter the following command, replacing123.123.1.23
with Host's IP address:If you changed the port number Host's OpenSSH server listens to, do:
Connect to Host and login via GUI file manager (e.g., Nautilus) for more visual SFTP access to enable file transfers
SSH
sshd_config
fileIn 14.04:
Create Standard User Accounts on Host with limited file permissions outside their home folder
Proper file permissions in place on Host guarantee that each standard user (without sudo privileges) that you create on Host will own their
/home/new_user
directory but have limited permissions with the rest of the directory structure.Hope that's helpful!