Skip to Content
SSH, The Secure Shell: The Definitive Guide, 2nd Edition
book

SSH, The Secure Shell: The Definitive Guide, 2nd Edition

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
May 2005
Intermediate to advanced
666 pages
21h 5m
English
O'Reilly Media, Inc.
Book available
Content preview from SSH, The Secure Shell: The Definitive Guide, 2nd Edition

The User rc File

The shell script /etc/ssh/sshrc is invoked by the SSH server for each incoming SSH connection. [5.6.3] You may define a similar script in your account, ~/.ssh/rc (OpenSSH) or ~/.ssh2/rc (Tectia), to be invoked for every SSH connection to your account. If this file exists, /etc/ssh/sshrc isn’t run.

The SSH rc file is much like a shell startup file (e.g., ~/.profile or ~/.cshrc), but it executes only when your account is accessed by SSH. It is run for both interactive logins and remote commands. Place any commands in this script that you would like executed when your account is accessed by SSH, rather than an ordinary login. For example, you can run and load your ssh-agent in this file:

    # ~/.ssh/rc, assuming your login shell is the C shell
    if ( ! $?SSH_AUTH_SOCK  ) then
      eval `ssh-agent`
      /usr/bin/tty | grep 'not a tty' > /dev/null
      if ( ! $status ) then
        ssh-add
      endif
    endif

Like /etc/ssh/sshrc, your personal rc file is executed just before the shell or remote command requested by the incoming connection. OpenSSH always uses the Bourne shell (/bin/sh) for ~/.ssh/rc, as it does for /etc/ssh/sshrc. In contrast, Tectia uses your login shell for ~/.ssh2/rc, unlike /etc/ssh2/sshrc.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Basics for Hackers

Linux Basics for Hackers

OccupyTheWeb .

Publisher Resources

ISBN: 0596008953Errata Page