Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I log into my linux user through ssh, the user should automatically execute a set of commands. Same thing when I log out of my user. How can I accomplish this?

share|improve this question
up vote 3 down vote accepted

Assuming your user's shell is bash, put commands to be executed in the files ~/.bash_login and ~/.bash_logout. The former is executed at login time (modulo certain configuration choices), and the latter at logout. There are analogues for most other shells.

share|improve this answer
What if I'm logging into /bin/false and my user doesen't have a home directory? – Schutzstaffel Nov 15 '12 at 15:16
If your user has no shell, (s)he can't log in, so the question doesn't apply. – MadHatter Nov 15 '12 at 15:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.