{"id":1888,"date":"2013-11-07T10:47:05","date_gmt":"2013-11-07T10:47:05","guid":{"rendered":"http:\/\/mccltd.net\/blog\/?p=1888"},"modified":"2013-11-11T19:58:05","modified_gmt":"2013-11-11T19:58:05","slug":"simple-bash-script-interactive-to-backup-netscreen-isg-ssg-firewall","status":"publish","type":"post","link":"http:\/\/darenmatthews.com\/blog\/?p=1888","title":{"rendered":"Simple Bash Script to Backup Netscreen ISG \/ SSG Firewall"},"content":{"rendered":"<p>This script is a simple, interactive way to backup and date-stamp your juniper Netscreen ISG\/SSG (ScreenOS) firewall configurations. The script copies the configurations from the firewall using scp. Configurations older than one day ( -mtime +1) are archived off to a bz2 compressed file.\u00a0 Archives older than 60 days ( -mtime +60 ) are removed from the disk.<\/p>\n<p>The usage is: <strong><span style=\"text-decoration: underline;\">nsb.sh<\/span> [<span style=\"text-decoration: underline;\">ip address \/ hostname of Netscreen<\/span>]<\/strong>.\u00a0 (<a href=\"http:\/\/darenmatthews.com\/blog\/?p=1888\"><strong>VIEW SCRIPT<\/strong><\/a>)<\/p>\n<p><!--more--><\/p>\n<p><strong><span style=\"text-decoration: underline;\">THE SCRIPT<\/span>:<\/strong><\/p>\n<p><code>#!\/bin\/bash<br \/>\nDATE=`date +%Y%m%d-%H%M%S`<br \/>\nDST=\/home\/amatthew\/netscreen\/backup\/<br \/>\nDEBUG=1<\/p>\n<p>getconfig()<br \/>\n{<br \/>\nif [[ $DEBUG -eq 1 ]]<br \/>\nthen<br \/>\necho scp netscreen@\"$1\":ns_sys_config ${DST}netscreen-$1\"-\"$DATE.conf<br \/>\nscp netscreen@\"$1\":ns_sys_config ${DST}netscreen-$1\"-\"$DATE.conf<br \/>\necho netscreen-$1\"-\"$DATE.conf saved to $DST<br \/>\nelse<br \/>\nscp -q -i $KEY netscreen@\"$1\":ns_sys_config ${DST}\/netscreen-$1\"-\"$DATE.conf<br \/>\nfi<br \/>\nfind $DST -type f -mtime +1 -name \"*.conf\" -exec bzip2 {} \\;<br \/>\nfind $DST -type f -mtime +60 -name \"*.bz2\" -exec rm -f {} \\;<br \/>\n}<\/p>\n<p>if [ \"$1\" == \"\" ]<br \/>\nthen<br \/>\necho \"usage $0 [ip address] \"<br \/>\nexit 1<br \/>\nelse<br \/>\ngetconfig $1<br \/>\nfi<br \/>\nexit 0<\/code><\/p>\n<p><strong>USAGE:<\/strong> Example:<\/p>\n<p><code>[dmatthews@mylinux ~]$ <strong>.\/nsb.sh 10.10.15.92<\/strong><br \/>\nscp netscreen@10.10.15.92:ns_sys_config \/home\/dmatthews\/netscreen\/backup\/netscreen-10.10.15.92-20131107-160742.conf<br \/>\nnetscreen@10.10.15.92's password:<br \/>\nns_sys_config 100% 177KB 59.2KB\/s 00:03<br \/>\nnetscreen-10.10.15.92-20131107-160742.conf saved to \/home\/dmatthews\/netscreen\/backup\/<\/code><\/p>\n<p><code>[dmatthews@mylinux ~]$ <strong>.\/nsb.sh 10.10.15.93<\/strong><br \/>\nscp netscreen@10.10.15.93:ns_sys_config \/home\/dmatthews\/netscreen\/backup\/netscreen-10.10.15.93-20131107-160757.conf<br \/>\nnetscreen@10.10.15.93's password:<br \/>\nns_sys_config 100% 177KB 59.1KB\/s 00:03<br \/>\nnetscreen-10.10.15.93-20131107-160757.conf saved to \/home\/dmatthews\/netscreen\/backup\/<br \/>\n[dmatthews@mylinux ~]$<br \/>\n[dmatthews@mylinux ~]$ <strong>ls -la netscreen\/backup\/<\/strong><br \/>\ntotal 728<br \/>\ndrwxr-xr-x. 2 dmatthews mcc 4096 Nov 7 16:08 .<br \/>\ndrwxr-xr-x. 3 dmatthews mcc 4096 Nov 5 10:28 ..<br \/>\n-rw-r--r--. 1 dmatthews mcc 181720 Nov 7 16:02 netscreen-10.10.15.92-20131107-160214.conf<br \/>\n-rw-r--r--. 1 dmatthews mcc 181720 Nov 7 16:07 netscreen-10.10.15.92-20131107-160742.conf<br \/>\n-rw-r--r--. 1 dmatthews mcc 181685 Nov 7 16:02 netscreen-10.10.15.93-20131107-160230.conf<br \/>\n-rw-r--r--. 1 dmatthews mcc 181685 Nov 7 16:08 netscreen-10.10.15.93-20131107-160757.conf<br \/>\n<\/code><br \/>\nIt is possible to use PKI to use SSL so that password authentication is not required (and thereby allowing the script to run without intervention) but if you are planning to backup clear-text configurations, it may be advisable to use this interactive version (contact me for PKI version of this script).<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>PREPARATION:<\/strong><\/span><\/p>\n<p><strong>1. Generate DSA Key Pair:<\/strong><\/p>\n<p>[dmatthews@mylinux ~]$ ssh-keygen -t dsa<br \/>\nGenerating public\/private dsa key pair.<br \/>\nEnter file in which to save the key (\/home\/dmatthews\/.ssh\/id_dsa):<br \/>\nEnter passphrase (empty for no passphrase):<br \/>\nEnter same passphrase again:<br \/>\nYour identification has been saved in \/home\/dmatthews\/.ssh\/id_dsa.<br \/>\nYour public key has been saved in \/home\/dmatthews\/.ssh\/id_dsa.pub.<br \/>\nThe key fingerprint is:<br \/>\n75:84:cd:56:d1:40:f7:fa:93:67:d2:0e:ba:d5:20:3f dmatthews@mylinux.mydomain.com<br \/>\nThe key&#8217;s randomart image is:<br \/>\n+&#8211;[ DSA 1024]&#8212;-+<br \/>\n| +.o=+.|<br \/>\n| ..+ .o|<br \/>\n| &#8230; .|<br \/>\n| . . . |<br \/>\n| S . o |<br \/>\n| o =.|<br \/>\n| Eo*|<br \/>\n| o *o|<br \/>\n| o. .|<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n[dmatthews@mylinux ~]$ cd \/home\/dmatthews\/.ssh\/<br \/>\n[dmatthews@mylinux .ssh]$ ls<br \/>\nid_dsa id_dsa.pub id_rsa id_rsa.pub known_hosts<br \/>\n[dmatthews@mylinux .ssh]$<\/p>\n<p><strong>2. Change permissions of .ssh directory:<\/strong><\/p>\n<p>[dmatthews@mylinux .ssh]$ chmod 755 ~\/.ssh<br \/>\n[dmatthews@mylinux .ssh]$<\/p>\n<p><strong>3. Copy Public Key to the machine that you wish to login to<\/strong> <em>(or for Netscreen firewalls create an Admin user and copy the public key &#8211; see further below):<\/em><\/p>\n<p>Copy the contents of ~\/.ssh\/id_dsa.pub into the file ~\/.ssh\/authorized_keys on the machine to which you want to connect. If the file ~\/.ssh\/authorized_keys exist, append the contents of the file ~\/.ssh\/id_dsa.pub to the file ~\/.ssh\/authorized_keys on the other machine.<\/p>\n<p>[dmatthews@mylinux .ssh]$ cat id_dsa.pub<br \/>\nssh-dss AAAAB3NzaC1kc3MAAACBAO3fxI\/yCK0xDVKDU0zkzKA\/tJAS4GS1tBaqitog7Joum8sl0ew73t7ydlwTXXmulVtiEt4zSHLS3z9WNvon24QOTy2ceivlZXgITNJa6OTAzZLbGsm8AYObGbScQWi5nkNxQtMAlAlMU1GcRBj4UAR3yZwVBQJxX3SmJJlWgYEXAAAAFQDQB0Fp3SR\/lF5ocdXJunErXU7hAwAAAIEAhY4aDkDwmOV3pT8WPY0EDB9d29u2oclvsyyUU2CluiNYHsC8prIN3yboph3CFeOSfXVh9JwhcGkPjmKp8wAfL91oT523EspXQAyamUFIvv5q5lT67GakO6Y6qBMm1+aVth2E8mLu5Mq7Ir+S\/Td68XtB9cERg4U3DnwwZhXKs9wAAACAfm0Lv10LQbyKCYdXMCgJlNg5x209Wvf\/HpLiqHXpTwEK1fLoyPmKl6dzA2byDGpJNDumuzJM\/Ym3li1gfkKz7fjeB9qMCVreXj+x2zvjRRch7fq5plfO2k1fNT6ZCYJxjMnFd1MaN5nIN9kvMA24UHmTT\/idVNbw\/H\/DYrv649g= dmatthews@mylinux.mydomain.com<br \/>\n[dmatthews@mylinux .ssh]$<\/p>\n<p><strong>4. Change Permissions of Authorised Keys file:<\/strong><br \/>\nchmod 600 ~\/.ssh\/authorized_keys<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>ON NETSCREEN (ScreenOS\u00a0 &#8211; ISG\/SSG):<\/strong><\/span><br \/>\nCreate [USER] user on Netscreen with Read only permissions from web:conf&gt; admin&gt; admins&gt; new<br \/>\nAdd [USER] user public key to Netscreen from web:conf&gt; admin&gt; admins&gt; configure-&#8220;ssh pka&#8221;&gt; add<\/p>\n<p><strong>NOTE:<\/strong> alternatively you can place the public key on a tftp server and import the key and bibnd it to the user via the CLI:<\/p>\n<p><strong>For SSHv1:<\/strong><br \/>\nexec ssh tftp <strong>pka-rsa<\/strong> [ username name ] file-name name_str ip-addr tftp_ip_addr<br \/>\n<strong>For SSHv2:<\/strong><br \/>\nexec ssh tftp <strong>pka-dsa<\/strong> [ user-name name ] file-name name_str ip-addr tftp_ip_addr<\/p>\n<p><em>The username or user-name options are only available to the root admin, so that only the root admin can bind an RSA key to another admin. When you\u2014as the root admin or as a read\/write admin\u2014enter the command without a user name, the NetScreen device binds the key to your own admin account; that is, it binds the key to the admin that enters the command.<\/em><\/p>\n<p><strong>NOTE:<\/strong> If you receive an &#8220;Invalid Key Encoding&#8221; message when pasting in via the WebUI\u00a0 it may be because the key blob is incorrectly entered:<\/p>\n<p>ssh-dss AAAAB3NzaC1kc3MAAACBAO3fxI\/yCK0xDVKDU0zkzKA\/tJAS4GS1tBaqitog7Joum8sl0ew73t7ydlwTXXmulVtiEt4zSHLS3z9WNvon24QOTy2ceivlZXgITNJa6OTAzZLbGsm8AYObGbScQWi5nkNxQtMAlAlMU1GcRBj4UAR3yZwVBQJxX3SmJJlWgYEXAAAAFQDQB0Fp3SR\/lF5ocdXJunErXU7hAwAAAIEAhY4aDkDwmOV3pT8WPY0EDB9d29u2oclvsyyUU2CluiNYHsC8prIN3yboph3CFeOSfXVh9JwhcGkPjmKp8wAfL91oT523EspXQAyamUFIvv5q5lT67GakO6Y6qBMm1+aVth2E8mLu5Mq7Ir+S\/Td68XtB9cERg4U3DnwwZhXKs9wAAACAfm0Lv10LQbyKCYdXMCgJlNg5x209Wvf\/HpLiqHXpTwEK1fLoyPmKl6dzA2byDGpJNDumuzJM\/Ym3li1gfkKz7fjeB9qMCVreXj+x2zvjRRch7fq5plfO2k1fNT6ZCYJxjMnFd1MaN5nIN9kvMA24UHmTT\/idVNbw\/H\/DYrv649g= dmatthews@mylinux.mydomain.com<\/p>\n<p>Only paste in:<\/p>\n<p>AAAAB3NzaC1kc3MAAACBAO3fxI\/yCK0xDVKDU0zkzKA\/tJAS4GS1tBaqitog7Joum8sl0ew73t7ydlwTXXmulVtiEt4zSHLS3z9WNvon24QOTy2ceivlZXgITNJa6OTAzZLbGsm8AYObGbScQWi5nkNxQtMAlAlMU1GcRBj4UAR3yZwVBQJxX3SmJJlWgYEXAAAAFQDQB0Fp3SR\/lF5ocdXJunErXU7hAwAAAIEAhY4aDkDwmOV3pT8WPY0EDB9d29u2oclvsyyUU2CluiNYHsC8prIN3yboph3CFeOSfXVh9JwhcGkPjmKp8wAfL91oT523EspXQAyamUFIvv5q5lT67GakO6Y6qBMm1+aVth2E8mLu5Mq7Ir+S\/Td68XtB9cERg4U3DnwwZhXKs9wAAACAfm0Lv10LQbyKCYdXMCgJlNg5x209Wvf\/HpLiqHXpTwEK1fLoyPmKl6dzA2byDGpJNDumuzJM\/Ym3li1gfkKz7fjeB9qMCVreXj+x2zvjRRch7fq5plfO2k1fNT6ZCYJxjMnFd1MaN5nIN9kvMA24UHmTT\/idVNbw\/H\/DYrv649g=<\/p>\n<p><strong>Validate scp and ssh configuration via the CLI:<\/strong><\/p>\n<p>Netscreen-&gt; get config | inc &#8220;set scp&#8221;<br \/>\nset scp enable<br \/>\nNetscreen-&gt; get config | inc &#8220;set ssh&#8221;<br \/>\nset ssh version v2<br \/>\nset ssh enable<br \/>\nset ssh pka-dsa user-name dmatthews pka-key-id 1823D75D5BCD3B356051<\/p>\n<p>Netscreen-&gt; set ssh ?<br \/>\nenable\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 enable SSH<br \/>\nhost-identity\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 bind host identity cert<br \/>\npka-dsa\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Bind a PKA DSA key\/cert to an admin user<br \/>\nversion\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 active ssh version<br \/>\nNetscreen-&gt; get config | inc pka-dsa<br \/>\nset ssh pka-dsa user-name dmatthews pka-key-id 1823D75D5BCD3B356051<br \/>\nNetscreen-&gt;<\/p>\n<p>Netscreen-&gt; get scp<br \/>\nSCP is enabled<br \/>\nSCP is ready<\/p>\n<p>Netscreen-&gt; get ssh<br \/>\nSSH V2 is active<br \/>\nSSH is enabled<br \/>\nSSH is ready for connections<br \/>\nMaximum sessions: 24<br \/>\nActive sessions: 1<\/p>\n<p>Admin\u00a0\u00a0\u00a0\u00a0\u00a0 Ip Addr\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Vsys\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Auth Method\u00a0 Service<br \/>\n&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8211;<br \/>\nnetscreen\u00a0 129.0.52.74\u00a0\u00a0\u00a0\u00a0 Root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 password\u00a0\u00a0\u00a0\u00a0 console<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This script is a simple, interactive way to backup and date-stamp your juniper Netscreen ISG\/SSG (ScreenOS) firewall configurations. The script copies the configurations from the firewall using scp. Configurations older than one day ( -mtime +1) are archived off to a bz2 compressed file.\u00a0 Archives older than 60 days ( -mtime +60 ) are removed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[63,84,18,13],"tags":[34,4],"_links":{"self":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1888"}],"collection":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1888"}],"version-history":[{"count":22,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1888\/revisions"}],"predecessor-version":[{"id":1910,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1888\/revisions\/1910"}],"wp:attachment":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1888"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}