Score:1

ssh server show message after login successful

se flag

I have one debian ssh server question , I want to display a message after successful login I have used motd, but the localhost will display it. I don’t want the local machine to display it. I only want to display it after a specific user successfully logs in to ssh.

Score:1
hk flag

To display a message after a specific user successfully logs into SSH, there are a few steps that you can follow:

Create a file that contains the message you would like to display after the user logs in. For example, you can create a file called "ssh_message" and add your desired message in the file.

Modify the SSH configuration file (/etc/ssh/sshd_config) and add the following line at the bottom of the file:

ForceCommand echo "YOUR MESSAGE HERE"

Save the file and restart the SSH daemon using the following command:

sudo systemctl restart sshd

After following these steps, the message will be displayed after the specific user logs into SSH. This approach will bypass the "Message of the Day" (motd) feature and display your message directly to the user.

It is worth noting that modifying the SSH configuration file can potentially cause security issues if done improperly. As such, I recommend testing the changes in a non-production environment first and ensuring that the changes are in line with your organization's security policies.

sv flag
Good idea. Thanks.
Score:0
hr flag

I think modifying the sshd config may apply to all users, not necessarily just one single user.

Another approach would be to use SSHLog: https://github.com/sshlog/agent/

You could configure it to watch for successful logins for one or more users (e.g., jdoe) and then execute the command "write" on successful login to that user's TTY. For example, here's a config that I tested and does what you want:

events:
  - event: jdoe_logs_in
    triggers: [ 'connection_established']
    filters:
      username: 'jdoe' 
      require_tty: True
    actions:
      - action: message_about_lunch_money
        plugin: run_command_action
        command: bash 
        args: ["-c", "echo 'Hello {{username}} do not forget that $4.75 you owe me for lunch!' | write {{username}} /dev/pts/{{tty_id}}"]

Then when he logs in his MOTD will look like this:

Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-67-generic x86_64)
...
40 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

*** System restart required ***

Last login: Tue Apr 18 11:41:16 2023 from 127.0.0.1

Message from root@server on pts/20 at 11:48 ...
Hello jdoe do not forget that $4.75 you owe me for lunch!
EOF
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.