Debian Codegraph @

debian/tests/sftp-connection

raw symbols SCIP
1 #!/bin/bash
2
3 set -x
4
5 # Add local user
6 adduser --disabled-password --gecos "" sftp-user
7
8 # Configure SFTP
9 cat <<EOF >/etc/proftpd/conf.d/sftp.conf
10 <IfModule mod_sftp.c>
11 SFTPEngine on
12 Port 2222
13 SFTPLog /var/log/proftpd/sftp.log
14 SFTPHostKey /etc/ssh/ssh_host_rsa_key
15 SFTPAuthMethods publickey
16 SFTPAuthorizedUserKeys file:/etc/proftpd/authorized_keys/%u
17 DefaultRoot ~
18 RequireValidShell off
19 SFTPCompression delayed
20 </IfModule>
21 EOF
22
23 # Restart service
24 systemctl restart proftpd
25
26 # Generate a key
27 su - sftp-user -c "mkdir -p /home/sftp-user/.ssh"
28 su - sftp-user -c "ssh-keygen -t rsa -b 4096 -N '' -f /home/sftp-user/.ssh/id_rsa"
29
30 # Convert key to the correct format
31 mkdir -p /etc/proftpd/authorized_keys/
32 ssh-keygen -e -m RFC4716 -f /home/sftp-user/.ssh/id_rsa.pub | tee /etc/proftpd/authorized_keys/sftp-user
33
34 # Try to connect via SFTP
35 sftp -i /home/sftp-user/.ssh/id_rsa -o StrictHostKeyChecking=no -P 2222 sftp-user@localhost