connect server over net::ssh - ruby

hy
i write this code in my script
def connect_sql
Net::SSH.start( #host, #user, :port=>22, :verbose => :debug ) do |ssh|
puts ssh.exec!("./root/scripts/MysqlCleanInstance.sh #{#uid}")
end
end
The probleme is for etablish a conenction between two server we use dns .The DNS information are in /etc/resolv.conf.
i dont know why when i try to connect to another server i get this error:
, [2014-01-08T17:55:34.905977 #28115] DEBUG -- tcpsocket[3f87c7e6b534]: received packet nr 5 type 51 len 44
D, [2014-01-08T17:55:34.906129 #28115] DEBUG -- net.ssh.authentication.session[3f87c7e5b2b0]: allowed methods: publickey,password
D, [2014-01-08T17:55:34.906309 #28115] DEBUG -- net.ssh.authentication.methods.keyboard_interactive[3f87c7e58948]: keyboard-interactive failed
E, [2014-01-08T17:55:34.906487 #28115] ERROR -- net.ssh.authentication.session[3f87c7e5b2b0]: all authorization methods failed (tried none, publickey, hostbased, password, keyboard-interactive)
/var/lib/gems/1.8/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start': Net::SSH::AuthenticationFailed (Net::SSH::AuthenticationFailed)
from clean_instance.rb:87:in `connect_sql'

Make sure your SSH keys are in place. It appears you are not able to authenticate over SSH, even after all authentication methods have been tried.
The reason you are unable to connect to another server is likely because you are not able to authenticate with that other server using a SSH key, which I assume you were able to do with the first server.

Related

Pusher not able to establish connection

I'm trying to connect to the Liquid exchange's Stream API with pusher. Documentation here
I have constructed a function that is in line with the Pusher library's documentation. Link to that here
My current code looks like this:
require 'pusher-client'
channels_client = PusherClient::Socket.new('LIQUID', {
ws_host: 'tap.liquid.com'
})
and running that gives me an error message of:
D, [2019-08-20Txx:xx:xx.xxxxxx #xxxxx] DEBUG -- : Binding
pusher:connection_established to pusher_global_channel
D, [2019-08-20Txx:xx:xx.xxxxxx #xxxxx] DEBUG -- : Binding
pusher:connection_disconnected to pusher_global_channel
D, [2019-08-20Txx:xx:xx.xxxxxx #xxxxx] DEBUG -- : Binding pusher:error
to pusher_global_channel
D, [2019-08-20Txx:xx:xx.xxxxxx #xxxxx] DEBUG -- : Binding pusher:ping
to pusher_global_channel
If I try to run this after the first command:
channels_client.connect
...it refuses to connect.
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/pusher-client-0.6.2/lib/pusher-client/websocket.rb:17:in
`initialize': No connection could be made because the target machine
actively refused it. - connect(2) for "tap.liquid.com" port 80
(Errno::ECONNREFUSED)
The error comes from tcpsocket.new (Ruby https://ruby-doc.org/stdlib-2.5.1/libdoc/socket/rdoc/TCPSocket.html) in websocket line 17: https://github.com/pusher-community/pusher-websocket-ruby/blob/master/lib/pusher-client/websocket.rb
ws_host tap.liquid.com 80 seems to be invalid, https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol
I have tried using a secure connection, at least in the browser and got a 404 for ws and invalid request, which is good in this case, for https (https://tap.liquid.com/).
You need to configure ssl in the client configuration, but the pusher-client gem as well as one other I have found are pretty old. Maybe it is wise to switch to a more up-to-date library like https://github.com/pusher/pusher-http-ruby/blob/master/README.md
The example contains an option for activated SSL.

Rspec Testing SMTP Connection

Using RSpec, I would like to test the ability of my App to connect to my SMTP server without (necessarily) delivering any messages.
How can I open a connection (with login) to an SMTP email server and test/review the response received?
smtp = Net::SMTP.new 'mail.example.com', example_port
# smtp.enable_starttls_auto # uncomment this if starttls is needed
# smtp.enable_tls # uncomment this if ssl/tls is needed but starttls is not supported
smtp.start('mydomain.example.com') do
expect{ smtp.authenticate 'me#mydomain.example.com', 'mypassword', 'plain' }.to_not raise_error
end
Calling authenticate will raise a Net::SMTPAuthenticationError if the authentication fails.
Otherwise, it will return a Net::SMTP::Response, and calling status on the response will return "235".

Challenge response from CFEngine Server Failure while conencting cygwin to CFEngine

when i run from windows-7 with cygwin to connect CFEngine bersion 3.4.2
cf-agent -Bs 217.64.173.210
Challenge response from server 217.64.173.210/217.64.173.210 was incorrect!
I: Made in version 'not specified' of '/var/cfengine/inputs/update.cf' near line 47
!! Authentication dialogue with 217.64.173.210 failed
Challenge response from server 217.64.173.210/217.64.173.210 was incorrect!
I: Made in version 'not specified' of '/var/cfengine/inputs/update.cf' near line
and in /var/cfengine/inputs/update.cf on line 47 is
47 : perms => m("600"),
on cgwin in folder keys
/var/cfengine/ppkeys
localhost.pub
localhost.priv
root-MD5=b8825ba0a0e7017e34b15766d3b3ac58 (which is also at CFEngine Server Side shared ky)
on Cf-Engine Server Side
/var/cfengine/ppkeys/
localhost.priv
localhost.pub
root-MD5=b8825ba0a0e7017e34b15766d3b3ac58
With Regards
Sandeep
Did you also get the server to trust the client's key? like so:
cf-key -t root-MD5=b8825ba0a0e7017e34b15766d3b3ac58
(on the server)
Also, try restarting cf-serverd in verbose mode with the -v switch on the server, and watch what error messages you get on that end.

suddenly PossibleAuthenticationFailureError in amqp

I'm using the ruby amqp gem. I ran a AMQP.start event loop, but 'suddenlyit raised aPossibleAuthenticationFailureError` during the loop.
AMQP.start(amqp_config) do |connection|
channel = AMQP::Channel.new connection
channel.on_error do |channel, channel_close|
puts "Oops... a channel-level exception: code = #{channel_close.reply_code}, message = #{channel_close.reply_text}"
end
my_worker = MyWorker.new
my_worker.start
end
[amqp] Detected TCP connection failure
/home/raincole/.rvm/gems/ruby-1.9.3-p125/gems/amq-client-0.9.3/lib/amq/client/async/adapters/event_machine.rb:164:in `block in initialize': AMQP broker closed TCP connection before authentication succeeded: this usually means authentication failure due to misconfiguration. Settings are {:host=>"localhost", :port=>5672, :user=>"guest", :pass=>"guest", :vhost=>"/", :timeout=>nil, :logging=>false, :ssl=>false, :broker=>nil, :frame_max=>131072} (AMQP::PossibleAuthenticationFailureError)
The weird part is, my worker have received some messages before I got PossibleAuthenticationFailureError. It seems like that the configuration should be correct(and I checked it over and over again).
Are there other potential reasons for PossibleAuthenticationFailureError?
I recommend a 4 step approach to investigating this issue:
a) Eliminate the obvious - Are your credentials correct and is the user account alive and well (default = 'guest')? Are you connecting to the appropriate vhost (default = '/')?
$ rabbitmqctl list_users
Listing users ...
guest [administrator]
...done.
$ rabbitmqctl list_user_permissions guest
Listing permissions for user "guest" ...
/ .* .* .*
<your_vhost> .* .* .*
...done.
b) What do the rabbitmq connection logs say?
On a Mac OS installation of rabbitmq (using brew), the logs can be found in /usr/local/var/log/rabbitmq, but your log location could be elsewhere depending on OS and installation preferences.
You may see the following lines in the rabbit#localhost.log file. Not a lot of help...and so proceed to step (c). Otherwise, investigate as per what you see in the log.
=INFO REPORT==== 15-Feb-2013::00:42:21 ===
accepting AMQP connection <0.691.0> (127.0.0.1:53108 -> 127.0.0.1:5672)
=WARNING REPORT==== 15-Feb-2013::00:42:21 ===
closing AMQP connection <0.691.0> (127.0.0.1:53108 -> 127.0.0.1:5672):
connection_closed_abruptly
c) Is rabbitmq's listener (Erlang client) alive. Default port = 5672. Simplest way to check is to send a garbage message to that port and look for an 'AMQP' response:
$ telnet localhost 5672
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
asdasd
AMQP
Connection closed by foreign host.
(d) Is the event loop reactor closing prematurely, before the AMQP.connect (or AMQP.start) actions have had a chance to complete authentication?
EM.run
connection = AMQP.connect(:host => 'localhost', :vhost => '/') do
# your code here
end
EM.stop
end
With all 'your code' sitting in a callback, the EM.stop runs instantaneously after the AMQP.connect instruction. This gives no time for the connection to be suitably established.
What worked for me here was to add a timer and handle disconnects gracefully.
EM.run
connection = AMQP.connect(:host => 'localhost', :vhost => '/')
# your code here
end
graceful_exit = Proc.new {
connection.close { EM.stop }
}
EM.add_timer(3, graceful_exit)
end
The reason I put the EM.stop block in a Proc is so that I can reuse it for other graceful exits (say, when trapping 'TERM' and 'INT' signals)
Hope this helps.

Ruby IMAP login error exception

With my Ruby script:
imap = Net::IMAP.new('imap.gmail.com')
imap.login("some_email#host.com", password)
I get the following exception:
A connection attempt failed because
the connected party did not properly
respond after a period of time, or
established connection failed because
connected hos has failed to respond. -
connect(2)
What's wrong?
You need to connect using SSL on port 993.
Therefore your code should be this:
imap = Net::IMAP.new('imap.gmail.com', 993, true)
imap.login("user#host.com", "password")

Resources