mysql -uroot -p —default-character-set=utf8 database
mysql> SET names ‘utf8’
mysql> SOURCE utf8.dump
mysql -uroot -p —default-character-set=utf8 database
mysql> SET names ‘utf8’
mysql> SOURCE utf8.dump
Add user
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password';FLUSH PRIVILEGES;
Update users passwordALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD'; FLUSH PRIVILEGES;
SFTP stands for SSH File Transfer Protocol. As its name suggests, it’s a secure way to transfer files between machines using an encrypted SSH connection. Despite the name, it’s a completely different protocol than FTP (File Transfer Protocol), though it’s widely supported by modern FTP clients.
SFTP is available by default with no additional configuration on all servers that have SSH access enabled. It’s secure and easy to use, but comes with a disadvantage: in a standard configuration, the SSH server grants file transfer access and terminal shell access to all users with an account on the system.
In some cases, you might want only certain users to be allowed file transfers and no SSH access. In this tutorial, we’ll set up the SSH daemon to limit SFTP access to one directory with no SSH access allowed on per-user basis.
To follow this tutorial, you will need access to an Ubuntu 18.04 server. This server should have a non-root user with sudo
privileges, as well as a firewall enabled. For help with setting this up, follow our Initial Server Setup Guide for Ubuntu 18.04.
First, create a new user who will be granted only file transfer access to the server. Here, we’re using the username sammyfiles, but you can use any username you like.
You’ll be prompted to create a password for the account, followed by some information about the user. The user information is optional, so you can press ENTER
to leave those fields blank.
You have now created a new user that will be granted access to the restricted directory. In the next step we will create the directory for file transfers and set up the necessary permissions.
In order to restrict SFTP access to one directory, we first have to make sure the directory complies with the SSH server’s permissions requirements, which are very particular.
Specifically, the directory itself and all directories above it in the filesystem tree must be owned by root and not writable by anyone else. Consequently, it’s not possible to simply give restricted access to a user’s home directory because home directories are owned by the user, not root.
Note: Some versions of OpenSSH do not have such strict requirements for the directory structure and ownership, but most modern Linux distributions (including Ubuntu 18.04) do.
There are a number of ways to work around this ownership issue. In this tutorial, we’ll create and use /var/sftp/uploads
as the target upload directory. /var/sftp
will be owned by root and will not be writable by other users; the subdirectory /var/sftp/uploads
will be owned by sammyfiles, so that user will be able to upload files to it.
First, create the directories.
Set the owner of /var/sftp
to root.
Give root write permissions to the same directory, and give other users only read and execute rights.
Change the ownership on the uploads
directory to sammyfiles.
Now that the directory structure is in place, we can configure the SSH server itself.
In this step, we’ll modify the SSH server configuration to disallow terminal access for sammyfiles but allow file transfer access.
Open the SSH server configuration file using nano
or your favorite text editor.
Scroll to the very bottom of the file and append the following configuration snippet:
. . .
Match User sammyfiles
ForceCommand internal-sftp
PasswordAuthentication yes
ChrootDirectory /var/sftp
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
Then save and close the file.
Here’s what each of those directives do:
Match User
tells the SSH server to apply the following commands only to the user specified. Here, we specify sammyfiles.ForceCommand internal-sftp
forces the SSH server to run the SFTP server upon login, disallowing shell access.PasswordAuthentication yes
allows password authentication for this user.ChrootDirectory /var/sftp/
ensures that the user will not be allowed access to anything beyond the /var/sftp
directory.AllowAgentForwarding no
, AllowTcpForwarding no
. and X11Forwarding no
disables port forwarding, tunneling and X11 forwarding for this user.This set of commands, starting with Match User
, can be copied and repeated for different users too. Make sure to modify the username in the Match User
line accordingly.
Note: You can omit the PasswordAuthentication yes
line and instead set up SSH key access for increased security. Follow the Copying your Public SSH Key section of the SSH Essentials: Working with SSH Servers, Clients, and Keys tutorial to do so. Make sure to do this before you disable shell access for the user.
In the next step, we’ll test the configuration by SSHing locally with password access, but if you set up SSH keys, you’ll instead need access to a computer with the user’s keypair.
To apply the configuration changes, restart the service.
You have now configured the SSH server to restrict access to file transfer only for sammyfiles. The last step is testing the configuration to make sure it works as intended.
Let’s ensure that our new sammyfiles user can only transfer files.
Logging in to the server as sammyfiles using normal shell access should no longer be possible. Let’s try it:
You’ll see the following message before being returned to your original prompt:
This service allows sftp connections only.
Connection to localhost closed.
This means that sammyfiles can no longer can access the server shell using SSH.
Next, let’s verify if the user can successfully access SFTP for file transfer.
Instead of an error message, this command will show a successful login message with an interactive prompt.
Connected to localhost.
sftp>
You can list the directory contents using ls
in the prompt:
This will show the uploads
directory that was created in the previous step and return you to the sftp>
prompt.
uploads
To verify that the user is indeed restricted to this directory and cannot access any directory above it, you can try changing the directory to the one above it.
This command will not give an error, but listing the directory contents as before will show no change, proving that the user was not able to switch to the parent directory.
You have now verified that the restricted configuration works as intended. The newly created sammyfiles user can access the server only using the SFTP protocol for file transfer and has no ability to access the full shell.
You’ve restricted a user to SFTP-only access to a single directory on a server without full shell access. While this tutorial uses only one directory and one user for brevity, you can extend this example to multiple users and multiple directories.
The SSH server allows more complex configuration schemes, including limiting access to groups or multiple users at once, or even limited access to certain IP addresses. You can find examples of additional configuration options and explanation of possible directives in the OpenSSH Cookbook. If you run into any issues with SSH, you can debug and fix them with this troubleshooting SSH series.
curl -sSL https://get.docker.com | sh
sudo usermod -aG docker pi
sudo docker run hello-world
sudo apt-get install libffi-dev libssl-dev python python-pip
sudo pip install docker-compose
https://hub.docker.com/r/superkikim/flicd-rpi3
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reload
To configure a static IP address on your Ubuntu 18.04 server you need to modify a relevant netplan network configuration file within /etc/netplan/
directory.
For example you might find there a default netplan configuration file called 01-netcfg.yaml
or 50-cloud-init.yaml
with a following content instructing the networkd
deamon to configure your network interface via DHCP:
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: yes
To set your network interface ens160 to static IP address 192.168.1.10
with gateway 192.168.1.1
and DNS server as 192.168.1.1 replace the above configuration with the one below.
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: no
addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.1]
Once ready apply changes with:
$ sudo netplan apply
In case you run into some issues execute:
$ sudo netplan --debug apply
INSERT INTO `s12kv_users` (`name`, `username`, `password`, `params`, `registerDate`, `lastvisitDate`, lastResetTime) VALUES (‘Administrator2’, ‘admin2’,‘d2064d358136996bd22421584a7cb33e:trd7TvKHx6dMeoMmBVxYmg0vuXEA4199’, ”, ‘2018-01-01 00:00:00’, ‘2018-01-01 00:00:00’, ‘2018-01-01 00:00:00’)
INSERT INTO `s12kv_user_usergroup_map` (`user_id`,`group_id`) VALUES (LAST_INSERT_ID(),'8');
UserBenchmarks: Game 19%, Desk 57%, Work 40%
CPU: Intel Core i7-2600K – 67.8%
GPU: Nvidia Quadro K2000 – 10.9%
SSD: Freenas iSCSI Disk 1TB – 23.9%
SSD: Intel(r) 910 200GB – 171.9%
SSD: Intel(r) 910 200GB – 172%
SSD: Intel(r) 910 200GB – 172%
SSD: Intel(r) 910 200GB – 172.1%
SSD: Freebsd iSCSI Disk 107GB – 29.3%
SSD: Intel 530 Series 240GB – 55.7%
HDD: Seagate ST3160815AS 160GB – 39.3%
RAM: Corsair Vengeance DDR3 1600 C9 4x4GB – 49.4%
MBD: Asus P8P67 PRO
UserBenchmarks: Game 27%, Desk 47%, Work 31%
CPU: Intel Core i5-4460 – 66.9%
GPU: Nvidia GTX 750 Ti – 22.4%
HDD: Seagate Desktop SSHD 1TB – 83.8%
RAM: Samsung M378B1G73QH0-CK0 1x8GB – 32.6%
MBD: Lenovo 90AV001HMW
Powered by WordPress