Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

Edited to reflect the problem I really wanted to solve:

I need to set up my ruby environment so I can deploy via Capistrano.

export PATH=$HOME/.rbenv/bin:$PATH
eval "$(rbenv init -)"

I put these in ~deploy/.profile, but when I ssh in, they aren't being run. Ideas?

I'm running Ubuntu 12.04.

The original question was:

When I ssh into another account at localhost, it doesn't load my .profile. How can I force ssh to load it? I'm running Ubuntu 12.04.

share|improve this question

You may explicitly specify that you want to start an interactive login shell:

 ssh user@host bash --login -i 

The "role" of ~/.profile (or ~./bash_profile) and .bashrc for ssh have some other files, (see man ssh for details):


Contains additional definitions for environment variables; see ENVIRONMENT, above.


Commands in this file are executed by ssh when the user logs in, just before the user's shell (or command) is started. See the sshd(8) manual page for more information.

share|improve this answer

.profile is only loaded for login shells, which an ssh session is not (by default). If you want something to run on startup for all interactive shells, put it in .bashrc instead (or .zshrc or whatever your shell uses).

Also, if you just want to log into another account on the local machine, ssh is probably overkill. You might want to use su or something instead.

share|improve this answer
It seems .bashrc is not loaded either. – kenorb Oct 2 '14 at 20:25
This is incorrect. It is a login shell. From the man page: "If command is specified, it is executed on the remote host instead of a login shell." – mkj Jul 23 '15 at 11:23

Using bash should result in reading ~/.bashrc. The following might help with ksh and sh (bash in sh mode), or when your ~/.bashrc is not executed during login.

The sshd consults ~/.ssh/environment (check sshd_config(5) for permissions) and ~/.ssh/sshrc or ~/.ssh/rc. This gives the possibility to setup ENV=~/.profile or BASH_ENV=~/.profile and SSH_LOGIN=Y

In ~/.profile I've the following layout (Replace ENV with BASH_ENV when using bash):

if [[ -n $SSH_LOGIN || -z $ENV ]]; then
     # Put here login initialization code
     unset SSH_LOGIN
 # Put here code thats get executed with each ksh/sh invocation

share|improve this answer

Because you are logging into another account. This account will have his own .profile. For global settings, use /etc/profile

share|improve this answer
This will be also ignored. – user86064 Mar 12 '13 at 21:40
Please provide proof for this assumption. – Squeezy Mar 12 '13 at 21:46
.profile and /etc/profile are loaded on interactive startup of a login shell. This is not connected to whether ssh sets environment variables, or runs startup commands. Using ssh to localhost will result in my .profile being loaded on my system. – Squeezy Mar 12 '13 at 21:52
interactive startup of a login shell - that's the point. If his ~/.profile is ignored, the global /etc/profile will be also ignored. – user86064 Mar 12 '13 at 21:53
I'd like to cite this for closing up, with the nice quote from the ssh man page When the user's identity has been accepted by the server, the server either executes the given command, or logs into the machine and gives the user a normal shell on the remote machine. All communication with the remote command or shell will be automatically encrypted. :… – Squeezy Mar 12 '13 at 22:35

You must log in to answer this question.

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