can't get paramiko to connect no matter what
i'm trying to connect to my vps with pythonista, but it doesn't seem to work.
When i run this, it just freezes after i enter the credentials.
No errors, nothing.
Any help would be greatly appreciated.
import paramiko import sys # ask for vps ip and current root password print 'vps ip:' vps_ip = raw_input() print 'current root password:' current_root_password = raw_input() # paramiko connect ssh = paramiko.SSHClient() try: ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=vps_ip, username='root', password=current_root_password) except: print 'error: ' print sys.exc_info() # execute remote command stdin, stdout, stderr = ssh.exec_command('uptime') stdin.close() for line in stdout.read().splitlines(): print line stdout.close() stderr.close() ssh.close()
You can do:
vps_ip = raw_input('vps ip:')
print 'vps ip:' vps_ip = raw_input()
Also see getpass() for getting the password from the user without echoing it to the screen.
If you put print statements before and after each of the four 'ssh' lines, which one is the last to run before the hang?
thanks for the tips.The script hangs before ssh.connect(...)
The code looks good. The line
ssh.load_system_host_keys()is not required, since you are auto-accepting any host key anyway, but I don't think it could cause problems.
You say that the script hangs before
ssh.connect(). I guess you mean it hangs when that line is executed, which would mean it is trying the connection without success.
The main suspect is then the value of
vps_ipvariable. Are you sure you are providing a valid IP? Perhaps your host is behind a NAT and you are using the private IP? Or there is some kind of firewall between you and your host?
To help the diagnosis, can you contact to the same IP from the same iPad, but using other SSH software (such as iSSH, for example)?
it works now, sorry for the trouble :)
What changes did you have to make to the code above?
None :) .
I checked my connection again with another iOS SSH client and it proved to be a DigitalOcean Amsterdam VPS issue.After i created a new droplet in New York, the IP worked.Thanx for a great piece of software, btw.