Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

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):

~/.ssh/environment

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

~/.ssh/rc

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 at 20:25

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
1  
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. : superuser.com/questions/479568/… –  Squeezy Mar 12 '13 at 22:35

Your Answer

 
discard

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.