To properly prevent access for a user on an SSH server, the correct solution is to modify the SSHD config so that they are explicitly denied access using the DenyUsers and/or DenyGroups settings. I would normally suggest using DenyGroups and creating a dedicated group for this purpose that you add anyone who is not supposed to have SSH access to.
To fully lock the account you also need to lock their password, set it expired (both using either usermod), and change their login shell to /sbin/nologin so that other login mechanisms do not let them in. You may need to do even more than that in some cases as well (for example, if the server runs Samba and the user had access to file shares through SMB, you probably need to lock their Samba account as well using smbpasswd).
Why is just locking the account with usermod not sufficient?
This comes down to the fact that an account is ‘locked’ in the traditional UNIX sense by making it such that no matter what password the user tries to use, it will never match what is in the password database. This means, rather importantly, that locking the account with usermod only affects those services which are authenticating against the system password database (on a modern Linux system this would mean those services which are configured to use the pam_unix PAM module for authentication).
However, SSHD only actually authenticates against the system password database if the password or challenge-response authentication mechanism is being used. Public key authentication, as well as any other authentication mechanisms (such as GSSAPI or s/key) only involve the system password database to check that the account exists, so they will generally work just fine with a locked account.
Why is setting the login shell to /sbin/nologin not sufficient?
This has to do with the fact that there are a number of ways to access a system as a specific user account that have nothing to do with a login shell.
The most relevant one here is that SFTP, SCP, and SSH with an explicitly specified command do not invoke a login shell at all. That means that even with the login shell set to /sbin/nologin, you can usually get a working shell on a system as a user by running ssh -t user@host /bin/sh (the -t is needed to explicitly request pseudoterminal allocation, which is in turn required to get some things, such as sudo or vim to work correctly from the resulting shell), and you can almost always still use SFTP and SCP to move files around.
Another example of this would be using sudo -u user /bin/sh to get a working shell as a given user from an existing session on the system as a different user. That will work even if the target user’s login shell is set to /sbin/nologin, though if the account is also locked using usermod you will have to run it as the root user (at least, in any standard sudo configuration).