1

I'm able to run a script automatically every time I log into my machine via SSH by placing a command in the /etc/ssh/sshrc file. That works perfectly, however it's only triggered when I log in via terminal or SFTP file browser like Transmit.

It does not run my script when I connect to a MySQL or MongoDB instance over SSH (where the database host is localhost through an SSH tunnel, see below).

How can I ensure this script gets run on every SSH connection to the server?

enter image description here

3
  • So you mean every time you get a new connection established over an already existing ssh tunnel? Mar 30, 2015 at 6:28
  • What is the screenshot from?
    – don.joey
    Mar 30, 2015 at 8:51
  • No these are new tunnels, not existing ones. Screenshot is from Sequel Pro, MySQL browser. sequelpro.com
    – 371273
    Mar 30, 2015 at 12:32

1 Answer 1

0

There are different ways:

  • use a ~/.ssh/rc script;
  • use the ForceCommand keyword in sshd.conf telling sshd to execute a command on every login (but this will also make sshd ignore any command supplied by the client and ~/.ssh/rc if present).
  • monitor /var/log/auth using a tool like logwatch.

I assume using a rc script is the easiest solution.

1
  • Options 1 and 2 did not work. My script is run when I log in via terminal, but not MongoDB/MySQL ssh tunnel.
    – 371273
    Mar 31, 2015 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .