Skip to content

Commit 99b93a9

Browse files
committed
Added an option to enable verbose logging
I added an option `sftp_enable_logging` that enables verbose logging for each user.
1 parent 06294f4 commit 99b93a9

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

defaults/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ sftp_group_name: sftpusers
44
sftp_directories: []
55
sftp_allow_passwords: False
66
sftp_enable_selinux_support: False
7+
sftp_enable_logging: False

handlers/main.yml

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
name: "{{ 'ssh' if ansible_os_family == 'Debian' else 'sshd' }}"
55
state: restarted
66
ignore_errors: Yes
7+
8+
- name: SFTP-Server | Restart rsyslog
9+
service:
10+
name: rsyslog
11+
state: restarted

tasks/main.yml

+17-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
ChrootDirectory %h
4040
AllowTCPForwarding no
4141
X11Forwarding no
42-
ForceCommand internal-sftp
43-
PasswordAuthentication {% if sftp_allow_passwords %}yes{% else %}no{% endif %}
42+
ForceCommand internal-sftp {{ sftp_enable_logging | ternary('-l VERBOSE', '') }}
43+
PasswordAuthentication {{ sftp_allow_passwords | ternary('yes', 'no') }}
4444
notify: SFTP-Server | Restart sshd
4545

4646
# Create each SFTP user with home directory on the correct partition, and add to SFTP group.
@@ -93,3 +93,18 @@
9393
with_nested:
9494
- "{{ sftp_users }}"
9595
- "{{ sftp_directories }}"
96+
97+
- name: SFTP-Server | Enable Logging
98+
blockinfile:
99+
dest: "/etc/rsyslog.d/{{ item.name }}.conf"
100+
create: yes
101+
block: |
102+
# Create an additional socket for some of the sshd chrooted users.
103+
$AddUnixListenSocket /home/{{ item.name }}/dev/log
104+
105+
# Log internal-sftp in a separate file
106+
:programname, isequal, "internal-sftp" -/var/log/sftp_{{ item.name }}.log
107+
:programname, isequal, "internal-sftp" ~
108+
with_items: "{{ sftp_users }}"
109+
when: sftp_enable_logging
110+
notify: SFTP-Server | Restart rsyslog

0 commit comments

Comments
 (0)