To set up an SFTP directory on a Linux server to receive files from multiple sources using shared accounts, follow these steps:
- Install OpenSSH server:
sudo apt-get install openssh-server
- Create a new user and group:
sudo useradd -m -s /bin/bash sftpuser
sudo groupadd sftpgroup
- Add the new user to the group:
sudo usermod -aG sftpgroup sftpuser
- Modify the sshd_config file:
sudo nano /etc/ssh/sshd_config
Add the following lines to the file:
Subsystem sftp /usr/lib/openssh/sftp-server
Match group sftpgroup
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
- Save and close the file, then restart the OpenSSH server:
sudo service ssh restart
- Change the ownership of the home directory for the new user:
sudo chown -R sftpuser:sftpgroup /home/sftpuser
- Create an empty .ssh directory and authorized_keys file in the home directory of the new user:
cd /home/sftpuser
mkdir .ssh
touch .ssh/authorized_keys
- Set the correct permissions for the .ssh directory and authorized_keys file:
sudo chmod 700 .ssh
sudo chmod 600 .ssh/authorized_keys
-
Share the SFTP account credentials with the users who will be uploading files.
-
To allow uploads from a shared account using SCP, the remote user should use the following command:
scp -o "PubkeyAuthentication=yes" -o "StrictHostKeyChecking=no" -P <port> -i <private_key_file> <source_file> sftpuser@<server_ip>:<destination_folder>
Replace <port> with the SSH port number, <private_key_file> with the path to the private key file, and <server_ip> and <destination_folder> with the server IP address and destination folder on the server, respectively.
For more information, refer to: