Use [[ ... ]]
instead of [ ... ]
to test a condition in Bash. The latter is poor in function and unmentioned in the official GNU Bash document at all.
passwd -l {username}
while the SSH key login is still possible for the user.
To enable the password login again:
passwd -u {username}
Note: this enable a user to login without a password!
passwd -d {username}