# .profile in UNIX

**URL:** <https://www.ruby-forum.com/t/profile-in-unix/155974>\
**Category:** Ruby\
**Created:** [December 18, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974 "2008-12-18T19:42:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 18, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/1 "2008-12-18T19:42:58Z")

</div>

Does anyone know how to access and use the .profile in UNIX while using  
NET::SSH in Ruby?

Thanks for the help

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 18, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/2 "2008-12-18T19:50:41Z")

</div>

Bob S. wrote:

> Does anyone know how to access and use the .profile in UNIX while  
> using NET::SSH in Ruby?
> 
> Thanks for the help

How to you mean? By updating it, parsing it from the file itself, or by  
using finger, or?

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 18, 2008, 7:56pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/3 "2008-12-18T19:56:20Z")

</div>

Tim G. wrote:

> How to you mean? By updating it, parsing it from the file itself, or by  
> using finger, or?

I believe we just need to load it into the session/channel so that we  
can use access/use command associated with the .profile

We are trying to run a command through Ruby but it seems that we need  
certain environmental properties set (e.g. .profile) in order to do  
this. If we log onto the server through Putty this command works just  
fine.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 18, 2008, 8:00pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/4 "2008-12-18T20:00:39Z")

</div>

Bob S. wrote:

> this. If we log onto the server through Putty this command works just  
> fine.

Sorry, I got you. I read the post too quickly and for some reason I  
thought you said .plan (I should have known that sounded strange).  
Indeed, the .profile is only set to work with shell, in the shell env,  
which is why CGI, web server APIs/modules and rails don’t read it. Did  
you need to set any environments or did you want to emulate or somehow  
use the shell vars naturally (assuming you can trust the  
user’s .profile)?

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 18, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/5 "2008-12-18T20:04:14Z")

</div>

Tim G. wrote:

> Sorry, I got you. I read the post too quickly and for some reason I  
> thought you said .plan (I should have known that sounded strange).  
> Indeed, the .profile is only set to work with shell, in the shell env,  
> which is why CGI, web server APIs/modules and rails don’t read it. Did  
> you need to set any environments or did you want to emulate or somehow  
> use the shell vars naturally (assuming you can trust the  
> user’s .profile)?

If the only way to get this to work is to set the environment/variables  
or emulate them somehow in the Ruby script, that is what we will need to  
do. Any idea as how to do this?

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 19, 2008, 4:00am UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/6 "2008-12-19T04:00:29Z")

</div>

On Dec 18, 2008, at 11:35 AM, Bob S. wrote:

> Does anyone know how to access and use the .profile in UNIX while  
> using  
> NET::SSH in Ruby?
> 
> Thanks for the help

you need to invoke a login shell on the remote host, then  
your .profile will be sourced.

probably there is some option to specify the remote shell for  
Net::SSH, specify something like

‘/bin/bash --login’

alternatively wrap your commands in something that does this for you  
like

cfp:~ \> cat `which bashenv`  
#!/bin/bash --login  
exec “$@”

and then invoke commands like ‘bashenv something.exe’

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 19, 2008, 6:55pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/7 "2008-12-19T18:55:10Z")

</div>

Bob S. wrote:

> Tim G. wrote:
> 
> > Sorry, I got you. I read the post too quickly and for some reason I  
> > thought you said .plan (I should have known that sounded strange).  
> > Indeed, the .profile is only set to work with shell, in the shell env,  
> > which is why CGI, web server APIs/modules and rails don’t read it. Did  
> > you need to set any environments or did you want to emulate or somehow  
> > use the shell vars naturally (assuming you can trust the  
> > user’s .profile)?
> 
> If the only way to get this to work is to set the environment/variables  
> or emulate them somehow in the Ruby script, that is what we will need to  
> do. Any idea as how to do this?

You can ‘source’ the .profile in your ssh session doing a:  
cmd=“. /home/user/.profile”

note the space after the dot.

Regards.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 19, 2008, 7:37pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/8 "2008-12-19T19:37:03Z")

</div>

On Thu, Dec 18, 2008 at 12:48 PM, Bob S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## this. If we log onto the server through Putty this command works just fine.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

If your server is running OpenSSH, you can also use ~/.ssh/environment.

See sshd(8) for details, under the LOGIN PROCESS section:

> **[sshd(8) - OpenBSD manual pages](https://man.openbsd.org/sshd.8)**

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 19, 2008, 8:31pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/9 "2008-12-19T20:31:36Z")

</div>

Thanks to all the help. We took some of your suggessions and some of our  
own hacking and got this to work.

thanks

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [December 19, 2008, 7:34pm UTC](https://www.ruby-forum.com/t/profile-in-unix/155974/10 "2008-12-19T19:34:41Z")

</div>

On Dec 19, 2008, at 12:47 PM, Rodrigo B. wrote:

> > > somehow  
> > > cmd=“. /home/user/.profile”
> 
> note the space after the dot.
> 
> Regards.

Read the docs about the intended use and behavior of ~/.profile or  
~/.login or ~/.bash\_login compared to ~/.bashrc

It’s probably in the INVOCATION section of the manual for your shell.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
