Show HN: Ssh2, simplifying EC2 ssh'ing
github.com
github.com
hardcoded paths like '/tmp/.ssh2_list' should not be used. This is insecure and wouldn't work on (most) multi user systems. Something like os.path.expanduser("~/.cache/ssh2_list") should be used instead.
f = open(cache_file_list, 'w')
f.write(output)
f.close()
can be written as with open(cache_file_list, 'w') as f:
f.write(output)
This: i = 0
for instance in all_instances:
i += 1
#..
print '%-4s%-55s%-30s' % ('[' + str(i) + ']',
instance['PublicDnsName'], name)
Simplifies to: for i, instance in enumerate(all_instances, 1):
choice = '[%d]' % i
name = extract_name(instance) #function instead of copy/paste
print '%-4s %-55s %-30s' % (choice, instance['PublicDnsName'], name)
Also would kind of make more sense to support matching on the name of the instance rather than requiring a number. In your case, 'ssh2 cron' makes a bit more sense than 'ssh2 0'https://github.com/soheil/ssh2/issues
I'd do it, but I have to run.
https://docs.python.org/2/library/tempfile.html
Additionally, a feature where the command line argument is applied as a wildcard search against the list of hosts would be nice, with the default behavior being to ssh into the first match when there's only one matching host.
Please, consider $XDG_CACHE_HOME. Not everyone likes the default directory layout.
I think, ugly-looking but reasonably portable version would look like
os.path.join(os.environ.get("XDG_CACHE_HOME", os.path.join(os.path.expanduser("~"), ".cache")), "ssh2_list")In this case it looks as if the blurred data is only IP addresses, so unlikely to cause any real damage on its own. But API keys, passphrases, private keys, and the like -- don't use gaussian blur. Crop them out or overwrite them entirely with an opaque color.
Also, don't put anything important in /tmp. As a practical matter it won't matter much if no one else has access to this machine. But it's a good habit to get into.
Thanks for the /tmp tip.
but it doesn't matter anyways. all IP addresses are by definition public; there are only about 4 billion of them anyways, less than there are people on Earth. you should probably focus more on making your code secure rather than obfuscating your IP address in screenshots.
for example, in addition to what has already been said about /tmp, system() is almost never the correct answer. in this case, if options.user or dns contain "special characters" they may be interpreted by the shell differently from what you intended.
On that note, you may also be interested in $XDG_RUNTIME_DIR (complex-ish semantics) or $XDG_CACHE_HOME (Default: ~/.cache/)
Host my-foo
HostName 54.xx.xx.xx
User my_user
IdentityFile ~/.ssh/server_key.pem
So, just:
ssh my-foo~/.ssh/config with identity files (certs) is the right way to ssh.
And ssh config entries can be used in other software, for example I use them in mc.
Consider something like mkstemp() or mkdtemp() instead (really, it should be marked 'insecure' until updated.)
https://docs.python.org/2/library/tempfile.html#tempfile.mkd...
It's a great idea and might work well w jumpbox config @ Userify ... I'll send over a pull request if I get a chance this week!
This tool would be good for temporary or autoscaling instances, though.
EC2 classic servers will also keep their IP addresses (and hence aws-assigned hostnames) through a reboot (in which the VM itself doesn't actually get torn down), but not through a stop/start cycle.
Edit: If your tool works for you, go for it. I don't mean to sound discouraging.
I'm working on adding VPC support.
I've also seen tab completion on `ssh` which matches EC2 IDs & "Name" tags, but can't find the project right now.
Thanks,