Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "non-absolute home" via Net:SSH

The code in question

Net::SSH.start('server name', 'user')

This returns "non-absolute home". The 'user' in fact does have a home directory. One suggested approach was to modify ~/.ssh/config with full paths to the IdentityFile. This did not solve the issue.

The crazy part of this is that the code works fine if called through irb or console. The moment we try calling it from within a class method (with the same code) it returns the "non-absolute home" error.

The 'user' can also ssh into the server via command line without issue. The server is running Ubuntu.

UPDATE

Thanks to @Phrogz - The fix for this was setting ENV['HOME'] to '/home/deploy'. However, I have not figured out why $HOME is getting set to "." on the server. So, I will leave this question up without an "Answer" until I, or someone else, figures that out. Having to manually set HOME feels more like a "hack" than a proper solution, but it does work.

like image 471
Jadon Avatar asked Apr 30 '12 22:04

Jadon


1 Answers

We just ran into the same problem, and found the root cause. We're running our script as a service, and if you check the manpage for service, it strips most env variables before running the script, including HOME. I don't know if your scenario is the same, but HOME is not set.

net-ssh wants to look up ssh config from the users home folder, so it used to force ENV['HOME'] to "." if it was not set. But when File.expand_path tries to expand "~/.ssh" the ArgumentError is raised.

This was fixed two months ago ( https://github.com/net-ssh/net-ssh/pull/98 ), so updating your net-ssh gem should resolve this.

like image 146
Stylpe Avatar answered Sep 25 '22 05:09

Stylpe