I'm in the situation of having to connect to various systems via ssh to do some quick work and then leave without a trace. Before I do any work, however, I would like to set up some aliases to save time, aliases that don't persist after my session is terminated.

Given the nature of the unknown environments, I want to avoid relying on .bash_profile and .bashrc since I don't want to check for, copy, parse, or in any way handle existing files beyond what's absolutely necessary for the work I'm doing.

Ideally, I should be able to add commands to be executed before my ssh login prompt inside ~/.ssh/rc, but I can't get ssh to execute the file when I make a connection.

I've made sure to enable the PermitUserRC option inside /etc/ssh/ssh_config.

Both .ssh/ and .ssh/rc have permissions set to 700.

How can I get ssh to execute ~/.ssh/rc?

I'm on MacOS Catalina 10.15.7 running zsh 5.7.1 inside Terminal 2.10.

  • You have ~/.ssh/rc set up on the target machine (the one you log in to) I assume. Usually running ssh -vv gives diagnostic output which could help (try more v to get more output).
    – nohillside
    Mar 9, 2022 at 18:15
  • ssh -vvvv doesn't seem to produce any smoking gun. It's all on the target machine, but if I can launch a normal interactive session on the tail end of an ssh command, a session with any motd, a prompt, and no surprises down the line, that would be an acceptable workaround. I'll look into that. Mar 9, 2022 at 19:07
  • Ah, PermitUserRC must be set in sshd_config, not in ssh_config. But the default (at least on macOS) is "enabled" so it shouldn't matter.
    – nohillside
    Mar 9, 2022 at 19:19
  • Good catch, but the option wasn't disabled in sshd_config either. I've ended up spawning a bash shell and supplying it with a temporary rc file by using bash's --rcfile. Unfortunately, zsh doesn't seem to have an equivalent option. Mar 10, 2022 at 22:20


You must log in to answer this question.

Browse other questions tagged .