{"id":1066,"date":"2017-02-19T11:42:54","date_gmt":"2017-02-19T17:42:54","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1066"},"modified":"2017-02-19T11:42:54","modified_gmt":"2017-02-19T17:42:54","slug":"ssh-password-manager","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/ssh-password-manager\/","title":{"rendered":"SSH password manager"},"content":{"rendered":"
I have recently started using a distro called BunsenLabs which is a Debian\/Openbox flavor. I run Linux inside VirtualBox and so far I really like this distro. \u00a0I have previously written about using Linux SSH connection managers like PAC(Perl Auto Connect), GCM, Remmina etc. \u00a0I have mostly settled on PAC for most Linux installations but it has a couple irritations and seem to be getting pretty old. \u00a0My goals is mostly to keep track of sometimes hundreds of machine names\/usernames\/passwords. \u00a0Couple options I have played with is putty from the command line and sshpass.<\/p>\n
For putty something like this could probably be built on:<\/p>\n
\r\n$ putty -load host01 -l root -pw mypass\r\n<\/pre>\nWith sshpass something like this works. Assuming you have sshpass to install on your distro.<\/p>\n
\r\n$ sshpass -p 'mypass' ssh -o StrictHostKeyChecking=no root@host01\r\nLast login: Sun Feb 19 11:11:45 2017 from 10.140.6.123\r\n[root@HOST01 ~]# \r\n<\/pre>\nSince I am using OpenBox here I added a custom OpenBox pipemenu by changing the existing SSH pipemenu a little bit. This works for me but I will probably change it a little bit in future to use a better config file with XML and\/or encrypting the details.<\/p>\n
Create a config folder and file to save the host details. For now config file is in SSH config format so the existing paramiko.config class can still read it. WARNING nothing about saving passwords like this is secure. You were warned!<\/p>\n
\r\n$ cat .sshpassdb\/config \r\nHost host01\r\n HostName host01.localdomain\r\n User root:mypass\r\n\r\n# Test complete command line that we will try in Openbox menus\r\n$ x-terminal-emulator -e sshpass -p 'mypass' ssh -o StrictHostKeyChecking=no root@host01\r\n<\/pre>\nNow lets add an Openbox pipemenu.<\/p>\n
Right click desktop -> Preferences -> Openbox -> GUI Menu Editor
\nExpand Openbox 3 and add a pipemenu. I called is SSH (sshpass) and pointed it to \/home\/myuser\/scripts\/bl-sshpass-pipemenu
\nI copied cp \/usr\/bin\/bl-sshconfig-pipemenu \/home\/myuser\/scripts\/bl-sshpass-pipemenu
\nEdit new this custom python file now to populate the Openbox custom menu when opened<\/p>\n$ cat scripts\/bl-sshpass-pipemenu <\/p>\n
\r\n#!\/usr\/bin\/env python\r\n# bl-sshpass-pipemenu - an Openbox pipemenu for Graphics applications\r\nimport os\r\nimport warnings\r\nwith warnings.catch_warnings():\r\n warnings.simplefilter("ignore")\r\n from paramiko.config import SSHConfig\r\nimport argparse\r\nimport sys\r\n\r\nap = argparse.ArgumentParser(description="""Openbox pipemenu to handle secure shell installation and configuration.\r\nThe install menu item is only shown when '\/usr\/sbin\/sshd' is not executable. """)\r\nopts = ap.parse_args(sys.argv[1:])\r\n\r\ncfgdir = os.getenv("HOME")+"\/.sshpassdb"\r\ncfgfile = cfgdir+"\/config"\r\n\r\ntry:\r\n config_file = file(cfgfile)\r\nexcept IOError:\r\n if not os.path.exists(cfgdir):\r\n os.makedirs(cfgdir, 0700)\r\n f = open(cfgfile, 'w')\r\n o = '# SSH config file, \\'man ssh_config\\' for more details.\\n\\n'\r\n o += '#Host example\\n'\r\n o += '# hostname example.com\\n'\r\n o += '# user joebloggs\\n'\r\n f.write(o)\r\n f.close()\r\n os.chmod(cfgfile, 0600)\r\n config_file = file(cfgfile)\r\n config = SSHConfig()\r\n config.parse(config_file)\r\n hosts = config._config\r\nelse:\r\n config = SSHConfig()\r\n config.parse(config_file)\r\n hosts = config._config\r\n\r\nprint '<openbox_pipe_menu>\\n'\r\n\r\nneed_separator = False\r\n\r\nif len(hosts) >= 2:\r\n for h in hosts[1:]:\r\n if 'host' in h and 'hostname' in h['config']:\r\n conf = h['config']\r\n user = ''\r\n if 'user' in conf:\r\n user = conf['user'].split(':')[0]\r\n passw = ' -p ' + conf['user'].split(':')[1] + ' '\r\n port = ['', '']\r\n if 'port' in conf:\r\n port[0] = '-p ' + conf['port'] + ' '\r\n port[1] = ':' + conf['port']\r\n if need_separator:\r\n print '<separator\/>\\n'\r\n need_separator = False\r\n print '<menu id="ssh-'+h['host'][0]+'" label="'+h['host'][0]+'">'\r\n print ' <item label="Start terminal session">'\r\n print ' <action name="Execute">'\r\n print ' <command>'\r\n print ' x-terminal-emulator -e sshpass ' + passw + 'ssh -o StrictHostKeyChecking=no ' + user + '@' + conf['hostname']\r\n print ' <\/command>'\r\n print ' <\/action>'\r\n print ' <\/item>\\n'\r\n print '<\/menu>\\n'\r\n print '<separator\/>\\n'\r\n\r\nif need_separator:\r\n print '<separator\/>\\n'\r\n need_separator = False\r\n\r\nprint '<\/openbox_pipe_menu>'\r\n<\/pre>\nTest with Right Click on desktop -> Network -> SSH (sshpass) and select a host -> Start terminal session.
\nAdd hosts to config file.<\/p>\n","protected":false},"excerpt":{"rendered":"I have recently started using a distro called BunsenLabs which is a Debian\/Openbox flavor. I run Linux inside VirtualBox and<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[77],"class_list":["post-1066","post","type-post","status-publish","format-standard","hentry","category-ssh","tag-openbox"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1066"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1066\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}