Unable to ping my remote machine using Ansible - ssh

I have a remote machine to which I want the connection to be set.
This is my hosts file:
[remote]
192.168.51.2
where 192.168.51.2 is the private ip of the remote machine.
When I try pinging it using ansible remote -m ping, I get the following error:
192.168.51.2 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}
I did not mention the credentials of that remote machine anywhere, but I don't think that's the problem here. It is failing to connect via SSH.
What do I do?

I did not mention the credentials of that remote machine anywhere, but I don't think that's the problem here. It is failing to connect via SSH.
This is the exact cause of your problem.
Ansible does not use a network (ICMP) ping, but a more complex procedure involving logging on to a remote machine via SSH and running Python script to respond.
You must provide the credentials either in the form of the private-public key-pair or a password.
Ansible basics are well documented and available here. The Remote Connection Information section of the Getting Started guide explains the way Ansible connects to remote hosts.

Leave the fingerprint of the master server to the remote server first before pinging to the remote server with ansible.
So "log in & log out the remote server first from the master server. Then, ping to the remote server with ansible."
I also couldn't ping to a remote server so I did the solution above ↑↑↑
Then, I could ping to the remote server.
I don't know what's happening backside but this solution will work.

Related

ssh tunnel VNC server connection closed unexpectedly

I have to tunnel the VNC server(tightvnc-server) running on my local machine to a remote server, so at remote server can access my local machine without port forwarding on router(at local machine network).
Right now I am using the following command
ssh -R 5950:localhost:5900 user#remote.ddns.net
Where 5900 the vnc server port on my local machine. And I have to access the machine from remote server using the command localhost:5950. And when I try to connect using vnc viewer I am getting the error connection closed unexpectedly. Normally if no connection exist I was getting connection refused error. But here something is missing in tunneling. Can any please tell me what could be the reason.
You need to activate the remote desktop, running:
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart \ -activate -configure -access -on \ -restart -agent -privs -all
Then you can connected using VNC Viewer

SCP times out, but ssh connection works fine. Am I doing something wrong?

I'm trying to copy task1.zip from my desktop /Users/myname/desktop if I pwd, to a remote server. I'm connected to the remote server via ssh. I would like to copy the file to /its/home/jt463/task1(pwd path from the directory) on the remote server.
I have used the command below in the terminal when I'm connected to the server via ssh and tried it on the terminal on my machine:
scp Users/myname/desktop/task1.zip username#inf900179.inf.susx.ac.uk:its/home/username/task1
Error that I get when I try to use the terminal that's connected to the remote server:
Users/jonatantibarovsky/desktop/task1.zip: No such file or directory
Error that I get when I try to use my local terminal:
ssh: connect to host inf900179.inf.susx.ac.uk port 22: Operation timed out lost connection
First scp to the intermediate server, using your credentials. Then, you should be able to scp from that server to the target.

Connecting erlang observer to remote machine via public IP

Background
I have a machine in production running an elixir application (no access to iex, only to erl) and I am tasked with running an analysis on why we are consuming so much CPU. The idea here would be to launch observer, check the processes tab and see the processes with the most reductions.
How am I connecting?
To connect I am following a tutorial from a blog:
https://sgeos.github.io/elixir/erlang/observer/2016/09/16/elixir_erlang_running_otp_observer_remotely.html 1
Their instructions are as follows:
launch the app in the production machine with a cookie and a name
from local run: ssh user#public_ip "epmd -names" to get the name of the app and the port used
from local create a ssh tunnel to the remote machine: ssh -L 4369:user#public_ip:4369 -L 42877:user#public_ip:42877 user#public_ip (4369 is the epmd port by default, 42877 is the port of the app)
from local connect to the remote machine using the node's name: erl -name "user#app_name" -setcookie "mah_cookie" -hidden -run observer
Problem
And now in theory I should be able to use observer on the machine. Instead however I am greeted with the following error:
Protocol ‘inet_tcp’: register/listen error: epmd_close
So, after scouring the dark side of internet, I decided to use sudo journalctl -f to check all the logs of the machine and I found this:
channel 3: open failed: administratively prohibited: open failed
my_app_name sshd[8917]: error: connect_to flame#99.999.99.999: unknown host (Name or service not known)
/scripts/watchdog.sh")
my_app_name CRON[9985]: pam_unix(cron:session): session closed for user flame
Where:
erlang -name: my_app_name
machine user: flame
machine public ip: 99.999.99.999 (obviously not real)
so it tells me, unknown host ?? I am confused since 99.999.99.999 is the public IP of the machine itself!
Questions
What am I doing wrong?
I read that in older versions of erlang I can’t monitor a machine with observer if they are in different networks (which is the case, because I want to monitor this machine from my localhost) but I didn’t find any information regarding this in modern days.
If this is in fact impossible, what alternatives do I have?
Solution
After 3 days of non-stop searching, I finally found something that works.
To summarize I am putting it here everything I did.
All steps in local machine:
get the ports from the remote server:
> ssh remote-user#remote-ip "epmd -names"
epmd: up and running on port 4369 with data:
name super_duper_app at port 43175
create a ssh tunel with the ports:
ssh remote-user#remote-ip -L4369:localhost:4369 -L43175:localhost:43175
On another terminal in your local machine, run a iex terminal with the cookie the app in your remote server is using. Then connect to it and start observer:
iex --name observer#127.0.0.1 --cookie super_duper_cookie
Node.connect :"super_duper_app#127.0.0.1"
> true
:observer.start
With observer started, select the machine from the Nodes menu.
Possible setbacks
If you have tried this and it didn't work there are a few things you can check for:
Check if the EPMD port on your local machine is free, if not, kill the process using it and free it.
Check your ssh tunneling keys and configurations for permissions. As #Roberto Aloi pointed out this link can be useful: https://unix.stackexchange.com/questions/14160/ssh-tunneling-error-channel-1-open-failed-administratively-prohibited-open

Dropbear SSH Tunnel disconnected if upload a file

i am newbie here.
I want to create ssh tunnel application,
but i have a problem with my application.
If I trying to upload a file (>500kb) trough that SSH Tunnel, my internet connection getting not responding and after that I'm disconnected from server.
what is the problem? do ssh server have a limit to upload connection?
*I use dropbear for ssh server

Executing a shell script on a remote host through ssh which inturn runs ssh to another host to apply database changes

I am trying to run a shell script on a remote host (A) through ssh. The shell script inturn uses SSH to connect to another host (B) to perform some database related operations. However it looks the agent is not being forwarded when connecting to Host B and I see a connection refused.
This is equivalent to executing ssh command as follows
ssh -A some#A.com "ssh some#B.com 'ls'"
I have used -A to enable agent forwarding but still no luck.
Please let me know how to achieve this? Thanks.
So silly of me. Firewall issue rather than ssh issue. Host A had no permission to connect to Host B. Should have thought this through! Thanks.