Unable to Attach to Remote Geth – Resolving Permission Denied Error

go-ethereumipc

I have created a shell script on a ubuntu server X with geth Node installed,to insert data in a smart contract in testnet blockchain. Further I am executing the shell script from a PHP file insertscript.php created on the same server X by using shell_exec command. When I call the PHP script from the command prompt , it gets successfully executed and data gets inserted in the blockchain . But when I call the php script from another server by using cURL or open it in the browser, I will see the error :

Fatal: Unable to attach to remote geth: dial unix ///home/ubuntu/.ethereum/testnet/geth.ipc: connect: permission denied

My shell script looks something like:-

#!/bin/sh
ATTACHPARAMETER="ipc:///home/ubuntu/.ethereum/testnet/geth.ipc"
INCIDENTUUID=${1:-"photo-55697b7f4a550511448499999999"}
USERUUID=${2:-"null"}
TIMESTAMP=$3
STATUS=$4

echo $INCIDENTUUID
echo $USERUUID
echo $TIMESTAMP
echo $STATUS

geth attach $ATTACHPARAMETER << EOF

var abi = [abi definition];
var address = "addressofContract";
var mycontract = web3.eth.contract(abi).at(address);
eth.defaultAddress = eth.accounts[0];
personal.unlockAccount(eth.accounts[0],'test');

mycontract.createIncident('$INCIDENTUUID','$USERUUID',$TIMESTAMP,$STATUS,{from:eth.accounts[0],gas:1400000});
console.log("Inserted");


EOF

Could you help in finding the cause of this error and also in finding a solution to the same?

Best Answer

This happens because your geth binary runs under one user_id, but the webserver runs under another user_id (probably nobody,www ,or etc)

You have to make the geth.ipc file readable and writable to your webserver, either by group access or by using the same user_id on both processes (the webserver and geth)

Also, note that you can not share geth access via IPC (Inter Process Communication) between 2 computers, the IPC works only inside a single computer because it is a kernel-level implementation of data sharing.