OK, let's see one by one
geth attach http://remote_ip:8545
Won't work: as geth attach
accepts as a parameter an ipc
entry (this is just a unix socket). There is a way to expose sockets remotely using socat
. I'll leave it as an exercise to the reader to find it.
web3.setProvider(new web3.providers.HttpProvider("http://remote_ip:8545"));
This one, connects with the remote RPC
(not the same as the IPC
). You need to expose your RPC
while launching geth
, with the options
--rpc --rpcport "8545" --rpcaddr "0.0.0.0" --rpccorsdomain "*"
SECURITY WARNING: Exposing both IPC or RPC conveys a security risk, as anybody able to find your machine, will have access. There is no built-in authentication inside geth
.
WHAT COULD YOU DO INSTEAD
I encourage you to adopt a more secure approach: Use SSH and attach this way
ssh -i <your private SSL key filepath> user@remote_ip "geth attach ipc:///<path to datadir>/geth.ipc"
Will open you an ssh tunnel to operate with the console. This is as secure and encrypted as it can be.