Technical Anshu
Tutorials Blog
Logs and Audit

Read SFTP Logs to See Who Connected and What Was Transferred

When a file goes missing or arrives somewhere it should not, opinions are cheap and logs are evidence. Ubuntu keeps the login records by default - this guide reads them, and adds the one setting that records the transfers themselves.

By Technical AnshuUbuntu Server8 minute read
Watch the complete Ubuntu SFTP server setup step by step in the video

Two different questions get asked of an SFTP server: who connected, when, from where - and which files moved. The first is answered by logs Ubuntu already keeps. The second needs a small verbosity change, because by default the file transfer subsystem minds its own business quietly. Both are covered here, along with the limits of what a log can prove.

/var/log/auth.log - a login, accepted and refused
Accepted password for ravi from 192.168.1.23 port 51244 ssh2
Failed password for admin from 203.0.113.9 port 60112 ssh2
Disconnected from authenticating user admin 203.0.113.9
Real log line shapes with example addresses. Accepted lines name the account and its source; failed lines are your early warning system.
1

Where the Login Records Live

On Ubuntu, SSH writes to /var/log/auth.log, and the same events are in the journal:

  1. sudo grep "sshd" /var/log/auth.log | tail -50 for the recent story
  2. sudo journalctl -u ssh --since today for a time-window view
  3. Filter by a person with sudo grep "for ravi" /var/log/auth.log

Every successful login records the account, the source address and the time. A key login additionally records which key was used when verbose login logging is on, which is why one person per account and per key matters - a shared account name in this log proves almost nothing.

2

Failed Logins Are a Signal, Not Noise

A handful of failed attempts is a user mistyping. Hundreds of failures for accounts like root, admin or test, from addresses you do not recognise, is the internet knocking - normal for an exposed server, and the direct evidence behind the fail2ban guide in this series. Check the failures weekly even when nothing seems wrong; the week you stop looking is the week it matters.

3

Turn On Transfer Records

To record file operations themselves, ask the SFTP subsystem to talk more:

  1. In /etc/ssh/sshd_config, change the subsystem or jailed ForceCommand line to include the level: ForceCommand internal-sftp -l VERBOSE in the Match block, or for non-jailed users Subsystem sftp /usr/lib/openssh/sftp-server -l VERBOSE
  2. Also set LogLevel VERBOSE so login lines record the key fingerprint used
  3. sudo systemctl restart ssh
  4. Uploads and downloads now appear in /var/log/auth.log with the account, file name and action

One honest wrinkle: for jailed users, the server process is cut off from the normal logging socket by the jail itself, so transfer lines from inside a jail need a logging socket created inside the jail folder - an rsyslog extra listener is the standard tool. Login records for jailed users still arrive normally, so you always keep the who-and-when even before adding that refinement.

4

What Logs Can and Cannot Prove

Logs prove a connection happened, from an address, as an account, at a time, and with verbose logging, which files it touched. They do not prove which human sat at the keyboard - a stolen laptop with a saved key logs in as its owner. That is why logs are one control among several: unique accounts, keys with passphrases, and prompt removal of leavers. Keep the logs themselves somewhere they survive: they rotate, so for real history forward them or copy them off the server on a schedule, because the first thing a serious intruder edits is the record of the visit.

Watch the Full Video

See the whole Ubuntu SFTP setup done live, with the exact clicks and commands, in the Technical Anshu video.

Watch Full Video
Frequently Asked Questions

My server logs show failed logins for users that do not exist. Am I hacked?

Almost certainly not - you are being scanned, which is the background noise of the internet. Random names tried from foreign addresses is the classic pattern. It becomes urgent only if a real account succeeds from an address you do not recognise.

Why do I see logins but no file transfers in the log?

Because transfer logging is off by default. Add the verbose option to the SFTP subsystem or the jailed ForceCommand as shown in this guide, restart SSH, and file operations will start appearing in the auth log.

How long are the logs kept?

Ubuntu rotates them - typically a few weeks of auth logs are kept compressed on the machine. If you need months of history for audits, forward or archive them elsewhere; do not rely on the server alone.

This guide is based on the Technical Anshu Ubuntu SFTP server video - Stuck on a step? Ask in the video comments and you will get a reply.