1. Edit /etc/ssh/sshd_config and add these directives at the bottom:
Match User guest
Banner /etc/ssh/banner_guest
DenyUsers guest
Match all
- Change
guest with the actual username.
2. Create the banner file: sudo nano /etc/ssh/banner_guest, and type your message inside, for example:
+------------------+
| Get out of here! |
+------------------+
3. Restart the SSH server:
sudo systemctl restart ssh.service
The result would be:


EDIT:
Please note regardless in the above example PubkeyAuthentication is available and there is a valid /home/guest/.ssh/authorized_keys file the user will get Permission denied (publickey).
If PasswordAuthentication is available the user will be asked few times for their password and in the end will get Permission denied (password). So if you want to further tease him (or her), change the above directives in this way:
Match User guest
PasswordAuthentication yes
PubkeyAuthentication no
MaxAuthTries 20
Banner /etc/ssh/banner_guest
DenyUsers guest
Match all
For me the cleanest way is just show the message and kick them:
Match User guest
PasswordAuthentication no
PubkeyAuthentication no
MaxAuthTries 1
Banner /etc/ssh/banner_guest
DenyUsers guest
Match all
The result of the above will be identical as the result of the first suggestion but the message Permission denied (publickey) (Server refused our key) will not appear.
Match allto be the answer completed. This directive is needed in a case when the sectionMatch Useris not into the end of the configuration file. – pa4080 Apr 17 '17 at 19:23Match all, but in general cases, it is a good practice to write allMatchblocks to the end of the file. It is a know feature described in the manual pages and in many other questions around there, but it is not part of this question so I don't think it should be written in every config snippet here. But thank you for the suggestion. – Jakuje Apr 17 '17 at 19:26Banner ...andForceCommand /usr/lib/openssh/sftp-server. In this way users won't be able to login via SSH but they will be able to use SFTP, and also, they will receive the message. – pa4080 Apr 17 '17 at 21:07read/sleepafter thenologincommand, if you want to make PuTTY show the message to you. – Jakuje Apr 17 '17 at 21:15Matchdirectives need to go to the top of thesshd_config– Even thesshd_configman page clearly says: "Since the first obtained value for each parameter is used, more host-specific declarations should be given near the beginning of the file, and general defaults at the end." – Martin Prikryl Aug 25 '19 at 07:32