iPython ssh from Windows qtconsole to a remote iPython kernel - windows

I want to run an iPython kernel on a Linux box and then connect to it remotely on a windows machine. The ipython kernel works fine and I can connect a qtconsole to it locally on the Linux box.
On Windows I have installed ipython and paramiko as its ssh client.
I run the following command on Windows 7 x64 cmd
D:\...\.ssh>ipython qtconsole --IPythonConsoleApp.sshserver='user#hostname:22' --IPythonConsoleApp.sshkey='myKey' --IPythonConsoleApp.password='1234'
I get the following error:
[IPythonQtConsoleApp] Could not setup tunnels
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\IPython\frontend\consoleapp.py", line 289, in init_ssh
newports = tunnel_to_kernel(info, self.sshserver, self.sshkey)
File "C:\Python27\lib\site-packages\IPython\lib\kernel.py", line 245, in tunnel_to_kernel
if tunnel.try_passwordless_ssh(sshserver, sshkey):
File "C:\Python27\lib\site-packages\IPython\external\ssh\tunnel.py", line 87, in try_passwordless_ssh
return f(server, keyfile)
File "C:\Python27\lib\site-packages\IPython\external\ssh\tunnel.py", line 123, in _try_passwordless_paramiko
look_for_keys=True)
File "C:\Python27\lib\site-packages\paramiko\client.py", line 332, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "C:\Python27\lib\site-packages\paramiko\client.py", line 493, in _auth
raise saved_exception
SSHException: not a valid DSA private key file
The key is even created with RSA.
Has anybody had a success in connecting remotely from a Windows machine to a remote ipython kernel?

You say
The key is even created with *R*SA.
but
SSHException: not a valid *D*SA private key file
RSA and DSA are different algorithms.
Either create a DSA private key file, or configure ipython to use RSA.
(I am not familiar with ipython, so cannot advise on the specifics. Sorry.)

Related

PyCharm remote debugging timeout error possibly by port connection

I have set up PyCharm for remote debugging with the Python remote debug server configuration as described in PyCharm website on a Mac OS and a Linux (Debian 11.1) machine but I get a
socket.timeout: timed out
error.
In this configuration PyCharm emulates a server in the local machine where the PyCharm runs, and then a script running in a remote machine connects to that server. That server in turn tries to connect with the local machine.
It seems that there is a problem in the connection of the PyCharm server with the local machine, and possibly something with the port.
How can I check if the port is open (terminal commands or something else) or if there is something else blocking the connection?
This is the full error message:
Could not connect to <public ip address>: 12345
Traceback (most recent call last):
File "<path>/miniconda3/envs/env/lib/python3.9/site-packages/_pydevd_bundle/pydevd_comm.py", line 458, in start_client
s.connect((host, port))
socket.timeout: timed out
Traceback (most recent call last):
File "<path>/main.py", line 43, in <module>
pydevd_pycharm.settrace(<public ip address>, port=12345, stdoutToServer=True, stderrToServer=True)
File "<path>/miniconda3/envs/env/lib/python3.9/site-packages/pydevd.py", line 1689, in settrace
_locked_settrace(
File "<path>/miniconda3/envs/env/lib/python3.9/site-packages/pydevd.py", line 1745, in _locked_settrace
debugger.connect(host, port) # Note: connect can raise error.
File "<path>/miniconda3/envs/env/lib/python3.9/site-packages/pydevd.py", line 655, in connect
s = start_client(host, port)
File "<path>/miniconda3/envs/env/lib/python3.9/site-packages/_pydevd_bundle/pydevd_comm.py", line 458, in start_client
s.connect((host, port))
socket.timeout: timed out

How to create ODBC "DSN" for cross-platform testing?

I need a simple ODBC test scenario on WIN which I can configure very simply and be assured it is working in support of another question at Unix.SE.
In a nutshell I'm trying to setup a PyODBC/Python script connection from Debian 10 (192.168.1.2) to Windows 10 in KVM/QEMU virtual system (192.168.1.12).
First, on the Windows 10/KVM, I see the ODBC Data Source Administrator has a tab File DSN and Microsoft Text Driver. Can I use FileDSN to test Python PyODBC connection to ODBC using a simple CSV file in place of Server?? (My research with ODBC only finds running server instances).
Next, what I tried:
On Debian I installed ODBC Microsoft driver for Linux.
Shutdown the Windows 10 firewall, and I can ping in both directions:
$nmap -p 22 192.168.1.12 # Deb to Win
> Test-NetConnection 192.168.1.2 -p 22 # Win to Deb
On Windows 10/KVM I added a FileDSN with Microsoft Text Driver. I created a CSV file (odbc_test_01.csv) with simple header and one row of data (IE. {'ID' : 1, 'NAME' : 'FOO'})
Created a Jupyter Notebook to make testing easier. Here is my connection string and the results:
cn = pyodbc.connect(r'Driver={ODBC Driver 17 for SQL Server};' # Driver installed above
r'FILEDSN=odbc_test_01.csv;' # my attempt at FileDSN
r'SERVER=192.168.1.12;' # KVM IP tested with ping
r'Trusted_Connection=no;' # explicit; use UID/PWD
r'UID=<username>;' # Windows user name
r'PWD=<password>', # Windows user password
autocommit=True)
OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
Tried isql from Debian command line with same string:
isql -v -k ''Driver={ODBC Driver 17 for SQL Server};FILEDSN=odbc_test_01.csv;SERVER=192.168.1.12; Trusted_Connection=no;UID=<username>;PWD=<password>'
Similar pages here at SO:
Authenticate from Linux to Windows SQL Server with pyodbc
Python pyodbc connect to Sql Server using SQL Server Authentication
An ODBC "File DSN" is not a driver for accessing data in a file. It is a way to specify a DSN (connection information for a target database) as values in a standalone file instead of in a standard configuration file on Linux (e.g., /etc/odbc.ini) or in the Windows registry.
If you need to "clone" a Windows DSN entry for use in a Linux environment then you may find my dump_dsn utility helpful. It retrieves an ODBC DSN from the Windows registry and presents it in a form that you could use to recreate the DSN on Linux.
For example, say I had a DSN named "mssql199" on Windows and when I ran dump_dsn.to_text("mssql199") on it I got
[mssql199]
Driver=ODBC Driver 17 for SQL Server
Description=with UseFMTONLY
Server=192.168.0.199
Database=myDb
Encrypt=No
TrustServerCertificate=No
ClientCertificate=
KeystoreAuthentication=
KeystorePrincipalId=
KeystoreSecret=
KeystoreLocation=
UseFMTONLY=Yes
Trusted_Connection=No
To use that same DSN on a Linux box I would have to
copy that block into /etc/odbc.ini (or equivalent, for a "System DSN") or ~/.odbc.ini (for a "User DSN") to use DSN=mssql199, or
save that block with an [ODBC] header instead of [mssql199] to a file, e.g., /home/gord/mssql199_file.dsn (for a "File DSN") and use FILEDSN=/home/gord/mssql199_file.dsn
Edit re: "Can I use FileDSN to test Python PyODBC connection to ODBC using a simple CSV file in place of Server??"
No. An ODBC DSN or FILEDSN on the Windows box will only be useful to connect from the Windows box to a data source (either locally, or on some other machine). We cannot connect from one machine (e.g., Linux) to an ODBC DSN entry on another machine
I created an SQLite database. Then I added SQLite drivers for ODBC.

openssh 7.2 and certificate file

I've been using signed ssh keys on Ubuntu 14, which uses openssh 6.6 like this:
ssh -i path/private_key root#server
This tries to find file path/private_key-cert.pub and if it finds it and it is a certificate file, it is used to complete the ssh connection and I can ssh to the server. Works perfect!
However this does not work on a server with openssh 7.2. The message I get is
sign_and_send_pubkey: no private key for certificate "/private_key-cert"
Seems that there are changes between openssh versions 6.x and 7.2 . How can I make this to work using openssh 7.2?
Thanks

Cloudera Host Installation failure: Failed to detect Cloudera Manager Server

I'm trying to put a host on a hadoop cluster using the Cloudera Manager.
The two computers I am using for this are the following:
10.10.10.9 is supposed to be a DataNode and my first host
10.10.10.10 has the Cloudera Manager and will be the NameNode
The manager is having trouble with the "Cluster Installation" part of the "Add Hosts to the Cluster" scenario on the GUI.
I get the following error when the manager tries to detect the Cloudera Manager Server:
BEGIN host -t PTR 10.10.10.10
10.10.10.10.in-addr.arpa domain name pointer stardestroyer.riis.local.
END (0)
using stardestroyer.riis.local as scm server hostname
BEGIN which python
/usr/bin/python
END (0)
BEGIN python -c 'import socket; import sys; s = socket.socket(socket.AF_INET); s.settimeout(5.0); s.connect((sys.argv[1], int(sys.argv[2]))); s.close();' stardestroyer.riis.local 7182
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.gaierror: [Errno -2] Name or service not known
END (1)
could not contact scm server at stardestroyer.riis.local:7182, giving up
waiting for rollback request
I tried to do as Cheloute instructs in the following link, but it didn't seem to fix my issue. I also had a different error than the poster.
Cloudera Manager. Failed to detect Cloudera Manager Server
If the following is used on the commandline, there's no error.
python -c 'import socket; import sys; s = socket.socket(socket.AF_INET); s.settimeout(5.0); s.connect((sys.argv[1], int(sys.argv[2]))); s.close();' 10.10.10.10 7182
I'm not really sure how to fix this in the Cloudera Manager, though.
I found that I could have my system administrator delete my reverse DNS entry and the manager ended up working. I don't know if there is a better solution (there likely is), but this is the one I came up with.

SSH to EC2 linux instance from Windows

I'm setting up a "data analysis on the cloud" class and most of the students will probably be using Windows.
The students will have to set up EC2 Ubuntu instances and connect to them.
What is the easiest way to set up SSH for Windows XP-7?
I've tried PuTTY but Puttygen can only convert the public key to putty format if I manually add newlines in a text editor. This is too involved for the class of 80.
I've tried OpenSSH but I can't seem to find the correct permissions for the public key file. On Mac OS/Linux it's just chmod 600.
Is there a decent SSH client that supports Amazon's key format that I can set up easily?
The .pem file Amazon Web Services gives you is supported by the openssh client implementations, but for a Windows-based client that works directly with the .pem file without converting it with puttygen.exe, look into Bitvise Tunnelier.
If anybody's looking for windows 10 solution.
In Windows 10, you can use powershell.
Use below command.
ssh -i \..\location-to-pem-file.pem ubuntu#X.X.XXX.XXX
If ssh is not supported in your windows 10 machine, follow this url for installation.
I used it and suggested the same.
Another possible solution is to use PuTTY but follow Amazon's guide for doing so. I found some other guide's that weren't as clear in the steps but I was able to get PuTTYgen to work correctly when I used their guide.
Install PuTTY.
Follow Amazon's guide for converting your PEM file to the PuTTY PPK format.
Connect to your server!
As for newlines, maybe you need to run unix2dos or some other program that will fix that for you?
Step1: Download the keypair
The download will create a .pem file on your local system. It contains a private key that you can use to connect to the EC2 instance via SSH
Step 2: Launch your linux instance
Copy the public ip address for the future use to connect the linux instance
Step 3: Download puttyGen from https://the.earth.li/~sgtatham/putty/latest/w32/puttygen.exe
Step 4: Execute the PuttyGen exe and load the private key(the pem file you have downloaded while launching the instance)
Step 5: Save the private key, it will give the .ppk file which will be used to connect the linux instance
Step 6: Download and install the Putty software, open the putty, and paste the public ip address which you copied from the linux instance
Step 7: Now load the .PPK file which we have saved
Step 8: Choose yes from the alert window
Step 9: Login as ec-user
I borrowed the method giving in this video. https://youtu.be/P1erVo5X3Bs
Open power shell and run below commands. You can open power shell at any location by print powershell in the nevigation bar and press enter.
enter image description here
1.reset premission:
icals.exe key.pem /reset
2.check the current user id
whoami
3.add permision to specific user id
icacls.exe key.pem /grant:r "YOUR USER ID GIVEN BY WHOAMI"
4.remove permission of other user
icacls.exe .\ec2.pem /inheritance:r
Now it should work.
If anybody's looking for windows 10 solution.
icacls.exe .\Desktop\xxxx.pem /reset
icacls.exe .\Desktop\xxxx.pem /grant:r "$($env:USERNAME):(r)"
icacls.exe .\Desktop\xxxx.pem /inheritance:r
ssh -i .\Desktop\xxxx.pem ec2-user#54.229.xxx.x

Resources