<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2549337862784319946</id><updated>2026-09-08T07:00:47.436-06:00</updated><title type='text'>A Blog for Those With a  Big Appetite for IT Knowledge...</title><subtitle type='html'>This blog has been made to share the great stuff I have to deal with on a daily basis, as reminder to myself of every little battle I had won an lost, in this extremely complicated and beautiful IT World and also to make the life of those like me, a little bit easier whenever they have to fight the same battles I had fought in the past. :)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>63</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-8014304542646862816</id><published>2012-01-23T11:13:00.000-07:00</published><updated>2012-01-23T11:13:46.347-07:00</updated><title type='text'>Setting Up SSH Access with Radius Authentication on 3Com Switches (5500 and 4500 Family) using Microsoft Network Policy Services (NPS)</title><content type='html'>&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;I have been dealing with this for many days and I finally got it working ! I believe there are a lot of people out there that are also willing to implement something like this , but there is no much 3Com documentation out there to help themselves. Follow this tutorial step by step in order to start authenticating ssh access to 3Com switches (5500 Family and 4500 Family) using your active directory and the windows server 2008 Network Policy Server. I also think this procedure can be improved and I will keep working on it (check for updates later). I would also like to use the same authentication mechanism for the 3Com web interface. A very similar configuration can also be used to set up 802.1x port authentication on this switches (post coming soon ;) ). All comments are welcome at the bottom of the post ! Enjoy !&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Windows Server Side Configuration&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
1- Install NPS Role on Windows Server 2008&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP3tLdg7yg5XrYjj8FbQE-Kg1zYhzLIm4IzOONbTOpd5_FmEGmYs9r9FRoaJQj1X6dtNGXGMl5CorIxHLeBYoZ_RXKyM34K1dCqs5tb936APApISMx158Ns5Av4sCqLucSKfgApyXGFgYZ/s1600/Add+NPS+Role+01.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;241&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP3tLdg7yg5XrYjj8FbQE-Kg1zYhzLIm4IzOONbTOpd5_FmEGmYs9r9FRoaJQj1X6dtNGXGMl5CorIxHLeBYoZ_RXKyM34K1dCqs5tb936APApISMx158Ns5Av4sCqLucSKfgApyXGFgYZ/s320/Add+NPS+Role+01.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM7N1fN4LRMHIiIwlQum8eixqByHa6r3y6vhaEqfcu414vKlw6_GUJ0bQRdzilozviJj3Smf79_R-oMZ8cne5sp6Uq1heZV-kF5X3EGePcjyt-Fddl4AwMjPiG_KBJ2QbyS_cJg7kHnsxr/s1600/Add+NPS+Role+02.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;236&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM7N1fN4LRMHIiIwlQum8eixqByHa6r3y6vhaEqfcu414vKlw6_GUJ0bQRdzilozviJj3Smf79_R-oMZ8cne5sp6Uq1heZV-kF5X3EGePcjyt-Fddl4AwMjPiG_KBJ2QbyS_cJg7kHnsxr/s320/Add+NPS+Role+02.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkt_5x5DjuLPoXqP3iG259ICNCvEeNlqhkKT6_MzmNYr4gx-ROPvBbsqDELskz6c6rTenSlgKzQYBRwYiesOKw_38TRdHg1Q3FMTRscj2LGCIuUrTsI8Jw7EOpguVZ_xkYGbEkRq4_zmZH/s1600/Add+NPS+Role+03.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkt_5x5DjuLPoXqP3iG259ICNCvEeNlqhkKT6_MzmNYr4gx-ROPvBbsqDELskz6c6rTenSlgKzQYBRwYiesOKw_38TRdHg1Q3FMTRscj2LGCIuUrTsI8Jw7EOpguVZ_xkYGbEkRq4_zmZH/s320/Add+NPS+Role+03.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo7s3rui1VejROZwJN4HIK-zlOWQIkNDZMOV3BN8DTR3W35iRQ5NFHTmaXjcG7sBTocclp0f-n5vDRY3gq9E5RIxSZuELwteJ6iZWXHmVKqmpY11qQFtMHIK4zYXkvfaBEKbQFBeZ1izY0/s1600/Add+NPS+Role+04.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;236&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo7s3rui1VejROZwJN4HIK-zlOWQIkNDZMOV3BN8DTR3W35iRQ5NFHTmaXjcG7sBTocclp0f-n5vDRY3gq9E5RIxSZuELwteJ6iZWXHmVKqmpY11qQFtMHIK4zYXkvfaBEKbQFBeZ1izY0/s320/Add+NPS+Role+04.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYoGyF_UKVohIob_wO_iAwSOmEJsjpkKFsYYSypMM4zRQeeXGIRf8eONCbZnNOhx-Yrodw1Z61lrQMCjrWKTzuHTMzZKEoPzb1bCdLUmO05sixs_mGOQ4seSlMd2A81Y_teaA-JtDMFvmf/s1600/Add+NPS+Role+05.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYoGyF_UKVohIob_wO_iAwSOmEJsjpkKFsYYSypMM4zRQeeXGIRf8eONCbZnNOhx-Yrodw1Z61lrQMCjrWKTzuHTMzZKEoPzb1bCdLUmO05sixs_mGOQ4seSlMd2A81Y_teaA-JtDMFvmf/s320/Add+NPS+Role+05.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoI1CIRRQ1vN6VpOI4j7IwuPIpdOOHTXPo9NEbYgnSFacX2n_QKxQyBa2Xb6V1vYVulCWSBi7B1gUASkn32nQVr7kd2ESxhDvzEEz-P45xmRNbHTNkkiVVFqySWIn754VkjAwgVXrh0pa9/s1600/Add+NPS+Role+06.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoI1CIRRQ1vN6VpOI4j7IwuPIpdOOHTXPo9NEbYgnSFacX2n_QKxQyBa2Xb6V1vYVulCWSBi7B1gUASkn32nQVr7kd2ESxhDvzEEz-P45xmRNbHTNkkiVVFqySWIn754VkjAwgVXrh0pa9/s320/Add+NPS+Role+06.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO_3HNZbbLwb_BIzXDDeB2Q0bAnBvFQfAUSliHTw7T-CTs3zA4xyyF0blyDF46U04LaAKfxpCkHJU1-M5mHOBQTGhoOT8YLrga6NYeZpZud7ltWcuOLrwyR2LNLS3h9j1tbF7AoIqdA681/s1600/Add+NPS+Role+07.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;236&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO_3HNZbbLwb_BIzXDDeB2Q0bAnBvFQfAUSliHTw7T-CTs3zA4xyyF0blyDF46U04LaAKfxpCkHJU1-M5mHOBQTGhoOT8YLrga6NYeZpZud7ltWcuOLrwyR2LNLS3h9j1tbF7AoIqdA681/s320/Add+NPS+Role+07.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4NxrgZWWru4yLP3VtRnJeQ0-gcXNtQH8qLhaktTFseaB0zto3tbJVjjBE-XIoduE8MjiYmgcxQd9cjm4CbEJ-0peloDe-BPiK3FOaCuWcN585uYZSbIUcUDhmMMO1vSsH9-HyFNxGA7PX/s1600/Add+NPS+Role+08.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4NxrgZWWru4yLP3VtRnJeQ0-gcXNtQH8qLhaktTFseaB0zto3tbJVjjBE-XIoduE8MjiYmgcxQd9cjm4CbEJ-0peloDe-BPiK3FOaCuWcN585uYZSbIUcUDhmMMO1vSsH9-HyFNxGA7PX/s320/Add+NPS+Role+08.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
2- Define the RADIUS clients &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggVmwjUw-lzL4T-0KIaQ49M4GPnEtGuIX90cg5gP4bvSN4fy28JFeIB0YciMFSDn8ATxiEpPaqAz_DKv8diw6AkcJVkrA-_arj6SfFTrnuKybUAR-h5roQ9hrz5_yydgTB_GlqDoJALcBF/s1600/Open+NPS.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;171&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggVmwjUw-lzL4T-0KIaQ49M4GPnEtGuIX90cg5gP4bvSN4fy28JFeIB0YciMFSDn8ATxiEpPaqAz_DKv8diw6AkcJVkrA-_arj6SfFTrnuKybUAR-h5roQ9hrz5_yydgTB_GlqDoJALcBF/s320/Open+NPS.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBMdbVBDVPWcjuriQITDGCSJOWM65p06F1yx3QMgPa2E77J3Lrr_fiIk6S6BcqdnIk9f2OWPQ-8Rbxg65IjH5cVbCmZJFfg_jhdZbt7QsE9Vhecx4KCc4twVT76WdjKnm_Sa8sCk0ZNeVQ/s1600/NPS+02.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;220&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBMdbVBDVPWcjuriQITDGCSJOWM65p06F1yx3QMgPa2E77J3Lrr_fiIk6S6BcqdnIk9f2OWPQ-8Rbxg65IjH5cVbCmZJFfg_jhdZbt7QsE9Vhecx4KCc4twVT76WdjKnm_Sa8sCk0ZNeVQ/s320/NPS+02.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb01CtVGNP8QH3qMDwq_rVir8SYdqSIFaV3NWYU8I86_Rpg9f4ZsA5jK7I-sfsLf40zAgZTx99lvSN5KEOX8BU6l9_Lf8CL0Zl9SqXTQAr_AwR-szkmVWKnApY7VgnY_R9qV4FKd-XnJ2J/s1600/NPS+01.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb01CtVGNP8QH3qMDwq_rVir8SYdqSIFaV3NWYU8I86_Rpg9f4ZsA5jK7I-sfsLf40zAgZTx99lvSN5KEOX8BU6l9_Lf8CL0Zl9SqXTQAr_AwR-szkmVWKnApY7VgnY_R9qV4FKd-XnJ2J/s320/NPS+01.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg71uNU9gVFbVFPEAdYNZNVM0PFYCDYL0OailcALgv3d88XXtC997jvbWUONSn_u-FTcGlzRsxLac2BraxJGR0n3FuBTrQWKYv9EalKjDN7Q2iqCW1UQ6s_vdeyrB0YTIZ_CuBrHDg_w0ky/s1600/NPS+03.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;318&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg71uNU9gVFbVFPEAdYNZNVM0PFYCDYL0OailcALgv3d88XXtC997jvbWUONSn_u-FTcGlzRsxLac2BraxJGR0n3FuBTrQWKYv9EalKjDN7Q2iqCW1UQ6s_vdeyrB0YTIZ_CuBrHDg_w0ky/s320/NPS+03.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEism57NxeEIkYuqBqNsp3h63FFIxYt9oAkF8rzrDPfMSo4VaivxrZGPvHoo7BBgATlpF-36H5Nbv2Bjyfxl_5fBMGXcHZ5Nc8MlKfRmgi69gojwqNLZhEHKWdTkZfFe5HBnfx2CfWdM2Bmi/s1600/NPS+04.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEism57NxeEIkYuqBqNsp3h63FFIxYt9oAkF8rzrDPfMSo4VaivxrZGPvHoo7BBgATlpF-36H5Nbv2Bjyfxl_5fBMGXcHZ5Nc8MlKfRmgi69gojwqNLZhEHKWdTkZfFe5HBnfx2CfWdM2Bmi/s320/NPS+04.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5P6UfLUs1sNvJSijqOv-bq6xIXtBqEQBeST-BFDh5uAdS4hbUR5loZT_MlhtJbHCCXtASSjsWdJjBH_aAsKV2G8km8t_eplqqyZ5dLD9m0azDv4yJ5pEiKSjx1-GAh-JSvrHZ0MUbvbhq/s1600/NPS+05.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5P6UfLUs1sNvJSijqOv-bq6xIXtBqEQBeST-BFDh5uAdS4hbUR5loZT_MlhtJbHCCXtASSjsWdJjBH_aAsKV2G8km8t_eplqqyZ5dLD9m0azDv4yJ5pEiKSjx1-GAh-JSvrHZ0MUbvbhq/s320/NPS+05.PNG&quot; width=&quot;262&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV2qyCFe1Lalu9IGWaSXMitxc80GPs2wjKLgpevtCspOEi1SfKgir9lwSBHWybxLDHolpO3Gs4JaNai27_zMXTZyFsqrmg3AkupHsL4jIFXb26n61GHa0l2aeGNZkNlB7DkFtOibHNlqLQ/s1600/NPS+06.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;318&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV2qyCFe1Lalu9IGWaSXMitxc80GPs2wjKLgpevtCspOEi1SfKgir9lwSBHWybxLDHolpO3Gs4JaNai27_zMXTZyFsqrmg3AkupHsL4jIFXb26n61GHa0l2aeGNZkNlB7DkFtOibHNlqLQ/s320/NPS+06.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2SU6FxVClgQWo92eC7v2jThk9HLo6eIOmjrQQriDii1kW1CGkmOBVcj2i-gL5tVQtlt0oPhfCjNdpXZfIDt_Fj-AkAGpSYto7RZ-kRA8jtzDGSODRPHurE9zOUlZP1rURRameLwk0yZ4l/s1600/NPS+07.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2SU6FxVClgQWo92eC7v2jThk9HLo6eIOmjrQQriDii1kW1CGkmOBVcj2i-gL5tVQtlt0oPhfCjNdpXZfIDt_Fj-AkAGpSYto7RZ-kRA8jtzDGSODRPHurE9zOUlZP1rURRameLwk0yZ4l/s320/NPS+07.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTMZ1kQDCENx0c-I-eGyhiBBlg5LFIrz1YSOe8sso5LXpifki2Xh80Rwg4FK2xBLNQndSnSsdV56YGeOtJHSuYqGCMNw5_OqmJ8UFHdv4dQlOZrofcCus21gCFfORK-ifrqrmdFZ57iAD8/s1600/NPS+08.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;318&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTMZ1kQDCENx0c-I-eGyhiBBlg5LFIrz1YSOe8sso5LXpifki2Xh80Rwg4FK2xBLNQndSnSsdV56YGeOtJHSuYqGCMNw5_OqmJ8UFHdv4dQlOZrofcCus21gCFfORK-ifrqrmdFZ57iAD8/s320/NPS+08.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMiOvpDMzex4Ve5pteBC4liovaOs62qlk4ZjQu85fUtegy0WUKv_lBpfk-d65cApI3mEnKc9WVvqNmxVmSAtK9BFKzRFatkZcJJhfKxkvuIN6bQLz3Ny5vP7F3IguAxjwjGxnECkOj3yv1/s1600/NPS+09.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMiOvpDMzex4Ve5pteBC4liovaOs62qlk4ZjQu85fUtegy0WUKv_lBpfk-d65cApI3mEnKc9WVvqNmxVmSAtK9BFKzRFatkZcJJhfKxkvuIN6bQLz3Ny5vP7F3IguAxjwjGxnECkOj3yv1/s320/NPS+09.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyEM0qnsUNpj4Zj3dsdHfEDT7RkSXhlWkIMbgOJsENcKyPem4ywkZTZLKNxR-bbPp1Mp4g_E_UQ-gJ2rEXUeuSf8d_odePYWpsgIsbrDMkTDak1DUYaWYn1_Q8K_ecC_hmIMg-XLdBuOcY/s1600/NPS+10.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;319&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyEM0qnsUNpj4Zj3dsdHfEDT7RkSXhlWkIMbgOJsENcKyPem4ywkZTZLKNxR-bbPp1Mp4g_E_UQ-gJ2rEXUeuSf8d_odePYWpsgIsbrDMkTDak1DUYaWYn1_Q8K_ecC_hmIMg-XLdBuOcY/s320/NPS+10.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7-seaoEK71KsD5eDE0xClYFJHRX-KzbGvk6h6efCSU7EFX8pVzQB4H59g_sOxYoz8Hmy2XizwMHsRLje0jWJ5i_M8JMka1UlsX1GypXXU2Y75Jfc6YcrU-hOFxODsCBZJBv-0XD6r0tTM/s1600/NPS+11.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7-seaoEK71KsD5eDE0xClYFJHRX-KzbGvk6h6efCSU7EFX8pVzQB4H59g_sOxYoz8Hmy2XizwMHsRLje0jWJ5i_M8JMka1UlsX1GypXXU2Y75Jfc6YcrU-hOFxODsCBZJBv-0XD6r0tTM/s320/NPS+11.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
3- Modify Connection Request Policies using the Network Policy Server configuration Snap-in&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqgMokbV4hJnyE0O87HWcl6kt7B9Io4bcHH8w6lthkhu_Fq1oFA3Jj5cdOZ6TWX1rxUmTejT_GZwKqpNv0G4S5oS8sbdc1BwLXpQXM7tD_4UIayDHk5NMkY2Upkjm_hrGkc7hwCoAzH_A1/s1600/Duplicate+NPS+Policy.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;228&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqgMokbV4hJnyE0O87HWcl6kt7B9Io4bcHH8w6lthkhu_Fq1oFA3Jj5cdOZ6TWX1rxUmTejT_GZwKqpNv0G4S5oS8sbdc1BwLXpQXM7tD_4UIayDHk5NMkY2Upkjm_hrGkc7hwCoAzH_A1/s320/Duplicate+NPS+Policy.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmI6sF1q7ijgDa6Y9IYnMWWWqvc4rIa76mrXjdShzv8bKVIf_HEc7EnCTgxmRIHpq096K70zoRxpuckXa_R4n1QKeRfZn7-PR_gkF7f_iDEYWAfg8JmmpHWvYAfBRfXpkCRyoYZ3MCE8Gh/s1600/Duplicate+NPS+Policy+02.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmI6sF1q7ijgDa6Y9IYnMWWWqvc4rIa76mrXjdShzv8bKVIf_HEc7EnCTgxmRIHpq096K70zoRxpuckXa_R4n1QKeRfZn7-PR_gkF7f_iDEYWAfg8JmmpHWvYAfBRfXpkCRyoYZ3MCE8Gh/s320/Duplicate+NPS+Policy+02.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgtPGRISwYhUSCWh6yzYCcPu03ve3UJE_Li2GM3lpW-xCr4guhQE96wizpZTFAgHK45f1gf4QzgMaUWFAY8Q1JTLV5u4QOvsowOaMPNE_5FM6mEVlwEq6rVqyxaNCZlzwvZ8TySuT3dIsd/s1600/Rename+NPS+Policy+01.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;226&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgtPGRISwYhUSCWh6yzYCcPu03ve3UJE_Li2GM3lpW-xCr4guhQE96wizpZTFAgHK45f1gf4QzgMaUWFAY8Q1JTLV5u4QOvsowOaMPNE_5FM6mEVlwEq6rVqyxaNCZlzwvZ8TySuT3dIsd/s320/Rename+NPS+Policy+01.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtrEYHtgLYpmo1IM9JSmQaaQrkEaX0A1uvLeNdmM8og7DRd79MR3s2vIFge1ZucHoEuKSy4CsSLebeBlHtcp7c1oDBjJ6HpOf7Jjz-ux-BB0WwUrSfeQ1BY9K1QzyTTurwQl-4KUBxp1sZ/s1600/Rename+NPS+Policy+02.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtrEYHtgLYpmo1IM9JSmQaaQrkEaX0A1uvLeNdmM8og7DRd79MR3s2vIFge1ZucHoEuKSy4CsSLebeBlHtcp7c1oDBjJ6HpOf7Jjz-ux-BB0WwUrSfeQ1BY9K1QzyTTurwQl-4KUBxp1sZ/s320/Rename+NPS+Policy+02.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipzwhgN16YL657CH1hyphenhyphen-oP0cwoi-zXDvPKwHQN-_SHPo_tCafudC1BEyYhwv_hF_G2FcE-n0JsfigQ2UozUYss3m1cErUezksENkszs7oLvUclRXHaAN27jrCsVpQ0W4vZbS0a3zXq81ge/s1600/Modify+Policy+01.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipzwhgN16YL657CH1hyphenhyphen-oP0cwoi-zXDvPKwHQN-_SHPo_tCafudC1BEyYhwv_hF_G2FcE-n0JsfigQ2UozUYss3m1cErUezksENkszs7oLvUclRXHaAN27jrCsVpQ0W4vZbS0a3zXq81ge/s320/Modify+Policy+01.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGuqv1KMdFPcEtyFBAraT3xcHS-KvS_Aq_8BhxPAmufvrXpCIYdAbqs5etUaneMU3HWqQ2EpOX1MmWLF5Gl4vN0jjTjHYYMUDZGqbXQDlo_eVVHOMV0Fbgie14Kluu1Z5fY_nWLG31kNbb/s1600/Modify+Policy+02.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGuqv1KMdFPcEtyFBAraT3xcHS-KvS_Aq_8BhxPAmufvrXpCIYdAbqs5etUaneMU3HWqQ2EpOX1MmWLF5Gl4vN0jjTjHYYMUDZGqbXQDlo_eVVHOMV0Fbgie14Kluu1Z5fY_nWLG31kNbb/s320/Modify+Policy+02.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjELbJOQGOm0CfmtUlfR06jNixn6ch2lEoMftE4jrER0dIbf7ta03AU0tFTvTl_gxRt3T5dRPeB2n2dgVl7nGWvZVHbSiRh1Q7njRtwAfqjMMc7_eHC4tfdJrx0gbPpBy1-t6yUpnsIYlA9/s1600/Modify+Policy+03.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;261&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjELbJOQGOm0CfmtUlfR06jNixn6ch2lEoMftE4jrER0dIbf7ta03AU0tFTvTl_gxRt3T5dRPeB2n2dgVl7nGWvZVHbSiRh1Q7njRtwAfqjMMc7_eHC4tfdJrx0gbPpBy1-t6yUpnsIYlA9/s320/Modify+Policy+03.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW-Q9s38fBda6fBVclD8o-Eg0l5ci4M7-uBWV3O3sjCj925_MQ-OVmjWqigbaYvvFwjkDMUqakJ-3pMcAX3Dn2rcjehM6LtjEk_PZ8hLdC7tRyzmEj4MuJd2x14gKU7UZ5IMH3UPSLVQEj/s1600/Modify+Policy+04.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW-Q9s38fBda6fBVclD8o-Eg0l5ci4M7-uBWV3O3sjCj925_MQ-OVmjWqigbaYvvFwjkDMUqakJ-3pMcAX3Dn2rcjehM6LtjEk_PZ8hLdC7tRyzmEj4MuJd2x14gKU7UZ5IMH3UPSLVQEj/s320/Modify+Policy+04.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMPwCrYuW2aIvEigTHkwkaT_ssuHZJK-MR2ZVuD_T7W4yXHULkpyA9Ydu4YJPtFmaVaAW2yiGXI4aZJ3E1308BJM7ePNSwkRFNrAGQWkaemgFBfkpOBX45Icsj0FYNYmSedx4wVaQr4u5q/s1600/Modify+Policy+05.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;263&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMPwCrYuW2aIvEigTHkwkaT_ssuHZJK-MR2ZVuD_T7W4yXHULkpyA9Ydu4YJPtFmaVaAW2yiGXI4aZJ3E1308BJM7ePNSwkRFNrAGQWkaemgFBfkpOBX45Icsj0FYNYmSedx4wVaQr4u5q/s320/Modify+Policy+05.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqTv-XL6bpa7H5cBMZTja7SH9sNgUspgoc_iqsiFVsu5HuT2NOYpv-yKy2gpoLq1mKu3dVqC5Y0lGzeVzLP650O1qieBxb1goJ5Ctp07ABjHQwPEI9RI0iGy9jUhlmHdmwhimEEWUwmsQU/s1600/Modify+Policy+06.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqTv-XL6bpa7H5cBMZTja7SH9sNgUspgoc_iqsiFVsu5HuT2NOYpv-yKy2gpoLq1mKu3dVqC5Y0lGzeVzLP650O1qieBxb1goJ5Ctp07ABjHQwPEI9RI0iGy9jUhlmHdmwhimEEWUwmsQU/s320/Modify+Policy+06.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
5- Modify Standard Radius Attributes Dictionary on Windows Server 2008  by editing C:\Windows\System32\ias\dnary.xml to add SSH, FTP and  Terminal under the Login-Service Attribute. The Standard RADIUS only allow for Telnet login by default, therefore the dictionary modification is needed in order to add, SSH, FTP and Terminal as login options under the standard RADIUS implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQ6VyzetMM0H6YYzo4ZL9xw0tNffzqtjm-B_Y5nzeiQ-boSFiHLbbyqGQEimYhKRtDeqKmGyEmsnkfj70cmp-MW8U6JmWsxGgXF39DiF7FE7X86eDRORmJgU9zwEbApDNC4GyoddWqG6i_/s1600/Modify+Radius+Dictionary+01.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;226&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQ6VyzetMM0H6YYzo4ZL9xw0tNffzqtjm-B_Y5nzeiQ-boSFiHLbbyqGQEimYhKRtDeqKmGyEmsnkfj70cmp-MW8U6JmWsxGgXF39DiF7FE7X86eDRORmJgU9zwEbApDNC4GyoddWqG6i_/s320/Modify+Radius+Dictionary+01.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOZzqa6Tg7Xg-IDMwjjZFXr4PTBc8607ViSHOlbuBuh4xkBiPeGlI2fzlq7q7rVdPU6EkiDHHrC_eY10x1OHTRMpMVjm_Ey-ZdmKmVf1n9WaxiVdgEygJOWbKwB1X6bMgVKmy6mf5PI_L_/s1600/Modify+Radius+Dictionary+02.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOZzqa6Tg7Xg-IDMwjjZFXr4PTBc8607ViSHOlbuBuh4xkBiPeGlI2fzlq7q7rVdPU6EkiDHHrC_eY10x1OHTRMpMVjm_Ey-ZdmKmVf1n9WaxiVdgEygJOWbKwB1X6bMgVKmy6mf5PI_L_/s320/Modify+Radius+Dictionary+02.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihlUr9qbu0CXWzXl4OBF40rrUhrANp1ErjK_cdqczjGyDFZMzarjbDg6lPy-WDZAlBYdY45HvhkrHZOj9VdgBU_VDX7wp85RkEDC190xwN4wtB9SNvym_XyF5xvDbTaIzb9L2ySl1knHZf/s1600/Modify+Radius+Dictionary+03.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihlUr9qbu0CXWzXl4OBF40rrUhrANp1ErjK_cdqczjGyDFZMzarjbDg6lPy-WDZAlBYdY45HvhkrHZOj9VdgBU_VDX7wp85RkEDC190xwN4wtB9SNvym_XyF5xvDbTaIzb9L2ySl1knHZf/s320/Modify+Radius+Dictionary+03.PNG&quot; width=&quot;320&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;6- Restart the Windows Server (Sometimes a Service Restart is not enough and a Server Restart might be required for the SSH option to show up among the standard RADIUS options)&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOHm-gBnrtP82GO9tc-njpwJ0bFh5qxedLXea9vFn1LkfmLp7WlNmtnEoFIs67c5_xbN560j_jSItecKF9fg-SPGDYMBO1WuUejozZ2fCUtX8VCuwEum2546SwSyf0TjpUKPAIf6YcH_Yw/s1600/Modify+Radius+Dictionary+04+-+Close+NPS+and+Restart+NPS+Service.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;224&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOHm-gBnrtP82GO9tc-njpwJ0bFh5qxedLXea9vFn1LkfmLp7WlNmtnEoFIs67c5_xbN560j_jSItecKF9fg-SPGDYMBO1WuUejozZ2fCUtX8VCuwEum2546SwSyf0TjpUKPAIf6YcH_Yw/s320/Modify+Radius+Dictionary+04+-+Close+NPS+and+Restart+NPS+Service.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;&quot; style=&quot;clear: both; text-align: left;&quot;&gt;7- Modify the Standard Radius Attribute inside the corresponding Network Policy to allow clients to log in using SSH.&amp;nbsp; &lt;/div&gt;&lt;div class=&quot;&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqTv-XL6bpa7H5cBMZTja7SH9sNgUspgoc_iqsiFVsu5HuT2NOYpv-yKy2gpoLq1mKu3dVqC5Y0lGzeVzLP650O1qieBxb1goJ5Ctp07ABjHQwPEI9RI0iGy9jUhlmHdmwhimEEWUwmsQU/s1600/Modify+Policy+06.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqTv-XL6bpa7H5cBMZTja7SH9sNgUspgoc_iqsiFVsu5HuT2NOYpv-yKy2gpoLq1mKu3dVqC5Y0lGzeVzLP650O1qieBxb1goJ5Ctp07ABjHQwPEI9RI0iGy9jUhlmHdmwhimEEWUwmsQU/s320/Modify+Policy+06.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvm71oaB66llCnF7i-W1fBc6cm4jdHcQp7-Es7SR0NV-wBUH9GvSR5AyqLmQ8p7LQjhGWPNXOUkqQNGucXTrfdZAbYZSDqLGxaOfUQFeciog3RkN__38F-bpJagutedl2-XjOPm8WkwOU0/s1600/Modify+Policy+08.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;246&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvm71oaB66llCnF7i-W1fBc6cm4jdHcQp7-Es7SR0NV-wBUH9GvSR5AyqLmQ8p7LQjhGWPNXOUkqQNGucXTrfdZAbYZSDqLGxaOfUQFeciog3RkN__38F-bpJagutedl2-XjOPm8WkwOU0/s320/Modify+Policy+08.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgME02WW7BtmlTvaFJQFvMAmrzwPlchm92tTRcHuhSzQ1ISiMWROMaRaZ2dULcoN-C5dLk4jiTaMVqMjAe_mPkUFt2I696zIbm4UTKbNi3tBTk2IBMxrh_IU4n6CBdb8qmUJoh6isd7UJ4c/s1600/Modify+Policy+09.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;176&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgME02WW7BtmlTvaFJQFvMAmrzwPlchm92tTRcHuhSzQ1ISiMWROMaRaZ2dULcoN-C5dLk4jiTaMVqMjAe_mPkUFt2I696zIbm4UTKbNi3tBTk2IBMxrh_IU4n6CBdb8qmUJoh6isd7UJ4c/s320/Modify+Policy+09.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4gzp4WDaMamz7VGgZzXaoXu3W_4ZRfXkyYdMAbHmjLBY4P1W8RXXpDgHZeVDxn47F7xHss3fQF3MRQn_LniPnFrFp0b9DlbY6zT9hZtOGgBAIAJ6es2ZcJEUB-gXOBFyWMerm7bZZJrI6/s1600/Modify+Policy+10.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4gzp4WDaMamz7VGgZzXaoXu3W_4ZRfXkyYdMAbHmjLBY4P1W8RXXpDgHZeVDxn47F7xHss3fQF3MRQn_LniPnFrFp0b9DlbY6zT9hZtOGgBAIAJ6es2ZcJEUB-gXOBFyWMerm7bZZJrI6/s320/Modify+Policy+10.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8- Modify the Vendor Specific Attribute to provide the corresponding User Access Level. Once the client connecting to the switch through SSH have been authenticate, the RADIUS server needs to tell the switch what access level is this user allowed. 3Com switches support the following access levels:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;- Level 0 (Attribute Number 1, Attribute Value 0) - 3Com-Visit&lt;/li&gt;
&lt;li&gt;- Level 1 (Attribute Number 1, Attribute Value 1) - 3Com-Monitor&lt;/li&gt;
&lt;li&gt;- Level 2 (Attribute Number 1, Attribute Value 2) - 3Com-Manager&lt;/li&gt;
&lt;li&gt;- Level 3 (Attribute Number 1, Attribute Value 3) - 3Com-Administrator&lt;/li&gt;
&lt;/ol&gt;In this case we are going to provide the users of the WEM-Local-NetAdmin domain group with User Access Level 3 (Administrator), so the user will be able to run any commands on the switches. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirFe3qpssbwkgHQbn6Q275TWkoT5Mln9pY-YgP4-YoByK2kVhg-wZun70aCvPHAy8UoYHbFKKTpqwcTDUdCf0vzbwJ8d4vFm8if-6glK-j11ptnelIi9b9TdApDwHOhjz6GiZbfOeAnot1/s1600/Modify+Policy+12.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;241&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirFe3qpssbwkgHQbn6Q275TWkoT5Mln9pY-YgP4-YoByK2kVhg-wZun70aCvPHAy8UoYHbFKKTpqwcTDUdCf0vzbwJ8d4vFm8if-6glK-j11ptnelIi9b9TdApDwHOhjz6GiZbfOeAnot1/s320/Modify+Policy+12.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOt0A7_qypyq4Wtyv8DJ8Zc5KZzSnA_CdOsWlD7fm3Dcai-HiXhB1-cez8d4gvwHrnEFncKwU7ST4VjlkYl4D-UdERIeGo48oul7q7pn0gpQoqxSZsQhoo4BetGDQdPsHLPcfRhpLlCXSS/s1600/Modify+Policy+13.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;281&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOt0A7_qypyq4Wtyv8DJ8Zc5KZzSnA_CdOsWlD7fm3Dcai-HiXhB1-cez8d4gvwHrnEFncKwU7ST4VjlkYl4D-UdERIeGo48oul7q7pn0gpQoqxSZsQhoo4BetGDQdPsHLPcfRhpLlCXSS/s320/Modify+Policy+13.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQt-bACi-wEp_kQ8I66BZOqbXNGPO9E4ydT3VWgQ2zu6wxSs_ioLtH3fYXAoUAvbNEDUNDHvWbOjxU33BIcOI-0Sh3xENsBH5ORUg9itDdP38Ign_JNFKUXUhl-BoRvnk3x2RSKMa-f8oc/s1600/Modify+Policy+14.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;286&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQt-bACi-wEp_kQ8I66BZOqbXNGPO9E4ydT3VWgQ2zu6wxSs_ioLtH3fYXAoUAvbNEDUNDHvWbOjxU33BIcOI-0Sh3xENsBH5ORUg9itDdP38Ign_JNFKUXUhl-BoRvnk3x2RSKMa-f8oc/s320/Modify+Policy+14.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRB1k-2Q_dVWZPX2CleZPVLsze7IHllYEmorJmhlENQ8EWKcCP4gBunREw6MtQPdCOrjk49S98snJLFkSdvZ9C5nc-aBedr75_elY3l65iLrIuMlQwiarYv2EQyoRFysTmuTIaEaCoVbt-/s1600/Modify+Policy+15.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;224&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRB1k-2Q_dVWZPX2CleZPVLsze7IHllYEmorJmhlENQ8EWKcCP4gBunREw6MtQPdCOrjk49S98snJLFkSdvZ9C5nc-aBedr75_elY3l65iLrIuMlQwiarYv2EQyoRFysTmuTIaEaCoVbt-/s320/Modify+Policy+15.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9JR3g6MypOt4C_ZxbL82_ko9gqy-nwbhcT5oaAgJVC53-Ks7CMxtDPP9ZgCAUcVFWXwbVE7I5RNkY5wboYt8jBIgP4ttL3M11mN_8ttT6sdC3FaE88KGQLjaDPJ3w4CyBTvJan_jDTWLf/s1600/Modify+Policy+16.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;261&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9JR3g6MypOt4C_ZxbL82_ko9gqy-nwbhcT5oaAgJVC53-Ks7CMxtDPP9ZgCAUcVFWXwbVE7I5RNkY5wboYt8jBIgP4ttL3M11mN_8ttT6sdC3FaE88KGQLjaDPJ3w4CyBTvJan_jDTWLf/s320/Modify+Policy+16.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;3Com Switch Side Configuration&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
1- Set up a Radius Scheme on 3Com&lt;br /&gt;
&lt;br /&gt;
radius scheme domain_name&lt;br /&gt;
&amp;nbsp;server-type extended&lt;br /&gt;
&amp;nbsp;primary authentication IP_Address_Of_NPS_Server&lt;br /&gt;
&amp;nbsp;primary accounting IP_Address_Of_NPS_Server&lt;br /&gt;
&amp;nbsp;accounting optional&lt;br /&gt;
&amp;nbsp;key authentication systems2006&lt;br /&gt;
&amp;nbsp;key accounting systems2006&lt;br /&gt;
&amp;nbsp;timer realtime-accounting 15&lt;br /&gt;
&amp;nbsp;timer response-timeout 5&lt;br /&gt;
&amp;nbsp;retry 5&lt;br /&gt;
&amp;nbsp;user-name-format with-domain&lt;br /&gt;
&amp;nbsp;nas-ip IP_Address_Of_Switch&lt;br /&gt;
&amp;nbsp;calling-station-id mode mode2 uppercase &lt;br /&gt;
&lt;br /&gt;
2- Set up a Domain and link it to the corresponding Radius Scheme&lt;br /&gt;
&lt;br /&gt;
domain domain.local&lt;br /&gt;
&amp;nbsp;scheme radius-scheme domain_name local&lt;br /&gt;
&amp;nbsp;scheme lan-access radius-scheme domain_name&lt;br /&gt;
&amp;nbsp;scheme login local&lt;br /&gt;
&amp;nbsp;accounting lan-access radius-scheme domain_name&lt;br /&gt;
&amp;nbsp;authentication login radius-scheme domain_name local&lt;br /&gt;
&amp;nbsp;accounting login radius-scheme domain_name local&lt;br /&gt;
&amp;nbsp;access-limit enable 60&lt;br /&gt;
&amp;nbsp;idle-cut enable 20 2000&lt;br /&gt;
&lt;br /&gt;
3- Set up the VTY interfaces to allow for ssh connections and to use the Radius Authentication Scheme&lt;br /&gt;
&lt;br /&gt;
user-interface vty 0 4&lt;br /&gt;
&amp;nbsp;authentication-mode scheme&lt;br /&gt;
&lt;br /&gt;
4- Set up the SSH Server parameters&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;ssh-server source-ip ip_address&lt;br /&gt;
&amp;nbsp;ssh server authentication-retries 5&lt;br /&gt;
&lt;br /&gt;
5- Set up the SSH user that are allowed to log in using SSH. Ideally, I would like to specify a group, instead of a domain user (userid@wem.local), so that all users on that group are valid users for the 3Com switch, but I have not found the way to do that yet.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;ssh user admin authentication-type password&lt;br /&gt;
&amp;nbsp;ssh user admin service-type all&lt;br /&gt;
&amp;nbsp;ssh user userid@domain.local authentication-type password&lt;br /&gt;
&amp;nbsp;ssh user userid@domain.local service-type all &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Troubleshooting&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
1- Check the Windows Server Event Viewer for Security , under Windows Logs. Verify the events are being logged as Audit Success.&lt;br /&gt;
&lt;br /&gt;
2- Use Wireshark on the NPS Server and try to connect to the switch using SSH. Verify Radius parameters passed back from the NPS server to the Switch.&lt;br /&gt;
&lt;br /&gt;
3- Use &lt;a href=&quot;http://www.dialways.com/download/&quot;&gt;NTRadPing&lt;/a&gt; Test Utility freeware tool to test connectivity to the RADIUS server and check your parameters.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Recommendations&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This procedure should be improved so that there is no need to define each user using the ssh user statement. Ideally only the AD user group should be used.&lt;br /&gt;
&lt;br /&gt;
Implement the same authentication mecanism for the switch management web interface.&lt;br /&gt;
&lt;br /&gt;
Comments are welcome !</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/8014304542646862816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2012/01/setting-up-ssh-access-with-radius.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/8014304542646862816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/8014304542646862816'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2012/01/setting-up-ssh-access-with-radius.html' title='Setting Up SSH Access with Radius Authentication on 3Com Switches (5500 and 4500 Family) using Microsoft Network Policy Services (NPS)'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP3tLdg7yg5XrYjj8FbQE-Kg1zYhzLIm4IzOONbTOpd5_FmEGmYs9r9FRoaJQj1X6dtNGXGMl5CorIxHLeBYoZ_RXKyM34K1dCqs5tb936APApISMx158Ns5Av4sCqLucSKfgApyXGFgYZ/s72-c/Add+NPS+Role+01.PNG" height="72" width="72"/><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-5892813752997342974</id><published>2011-06-24T16:36:00.000-06:00</published><updated>2011-06-24T16:36:34.655-06:00</updated><title type='text'>Software RAID on Linux with mdadm</title><content type='html'>&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;RAID Controllers&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We’ve spent a great deal of time examining various RAID levels such as RAID-0, 1, 5, and 6, and Nested RAID levels such as RAID-10, 50, 51, 61, and 60 or even the more complicated RAID-100 or RAID-160. In all of these discussions we have assumed there was a RAID “controller” that performed the various RAID operations. This includes sending chunks of data to the appropriate disks, computing parity, hot-swapping, disk fail-over, checking read transactions to determine if the read was successfully and if not, declaring that disk as “down”, plus other important tasks related to RAID. All of these tasks require some sort of computation and have to be performed by a RAID controller.&lt;br /&gt;
&lt;br /&gt;
You really have two options for RAID controllers: (1) a dedicated RAID controller such as those on add-in RAID cards, (2) software RAID that uses the CPU for RAID chores. In the first case you have a dedicated RAID controller, typically on an add-in RAID card but it can be on a motherboard, that performs the necessary RAID computations. This controller typically uses a dedicated lower power processor, often a real-time processor such as a PowerPC, to perform the computations. Typically these controllers are put on an add-in card and you plug the drives you want in the RAID array into the card.&lt;br /&gt;
&lt;br /&gt;
With software RAID, all the RAID functions run on the CPU. Pretty much all Linux distributions comes with software RAID in the form of md (Multiple Device) which is a driver within Linux that provides virtual devices created from one or more underlying devices (e.g. storage block devices). Plus the great thing is that it comes with almost all Linux distributions so you have access to the source (plus the price isn’t too bad either and it has a great deal of functionality). In addition, you can create Nested RAID configurations as needed since all RAID functions are in software (I smell a Triple Lindy coming).&lt;br /&gt;
&lt;br /&gt;
One thing you have to be very careful about is what is commonly called a fakeRAID card or fakeRAID controller. FakeRAID is not hardware RAID because there is no dedicated RAID controller. Rather, they use a standard disk controller chip on an add-in card or motherboard, with some specialized firmware and drivers. At boot-time they run a special application that allows users to configure disks attached to the fakeRAID as a RAID group. But the RAID processing is really handled by the drivers which are run on the CPUs (so the CPU provides the computational power). Consequently, it’s really a software RAID solution and not hardware RAID (hence the name “fakeRAID”).&lt;br /&gt;
&lt;br /&gt;
There is a great deal of discussion and grinding of teeth within the Linux community about fakeRAID. One point of the discussions is that the vendors of fakeRAID don’t tell customers that what they are actually buying is not a RAID card with a dedicated RAID controller, but rather a simple card with a disk controller coupled with drivers that use the CPU for RAID processing (false advertising). Plus there is the additional problem of developing and supporting drivers for Linux to allow these fakeRAID cards to be used. Moreover, there is a strong argument that it is probably better to use software RAID that comes with Linux (md) since it is already part of Linux and can arguably give you better performance.&lt;br /&gt;
&lt;br /&gt;
However, if you want to use software RAID that comes with Linux in the kernel (md), you still need some tools to control/manage/monitor the software RAID arrays. That’s where mdadm comes in. This article will do a brief examination of mdadm and some of its options.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Introduction to mdadm&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Mdadm is a software tool primarily written by Neil Brown that allows you to create, assemble, report on, grow, and monitor RAID arrays that use software RAID in Linux. Actually according to the documentation there are seven modes of operation:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; 1. Create&lt;br /&gt;
&amp;nbsp;&amp;nbsp; 2. Assemble&lt;br /&gt;
&amp;nbsp;&amp;nbsp; 3. Follow or Monitor&lt;br /&gt;
&amp;nbsp;&amp;nbsp; 4. Build&lt;br /&gt;
&amp;nbsp;&amp;nbsp; 5. Grow&lt;br /&gt;
&amp;nbsp;&amp;nbsp; 6. Manage&lt;br /&gt;
&amp;nbsp;&amp;nbsp; 7. Misc&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We’ll walk through these various modes of operation but the focus of this article is an introduction and not an in-depth HOWTO. You can find those types of articles on the web.&lt;br /&gt;
&lt;br /&gt;
The first step in using mdadm, or any RAID for that matter, is to PLAN your RAID configuration carefully. Personally I like to work backwards starting with the purpose of the storage. Will it be used for a database? Will it be used for /home? Will it be used for high-speed scratch? Will it be used for data that requires a very high degree of reliability? Understanding the intent of the storage is really the key to creating the RAID configuration you need/want. Once you determine the storage use case, you need to develop an idea of how much I/O performance you need (throughput and IOPS) and the general ratio of read and write performance. You should also develop an idea of how much data redundancy you need for the storage.&lt;br /&gt;
&lt;br /&gt;
Once you have an idea of the performance and redundancy of the array you can select the RAID configuration you think you might need. I would suggest you select a few candidate RAID configurations and then do some more reading/research on each one and select the RAID configuration that seems to be best. During this research be sure to examine the redundancy as well as the performance of the various RAID configurations and compare them to your estimations. But also be sure to examine the capacity and storage efficiency of each level. You may love the performance and storage efficiency of RAID-10 but the data redundancy may not be enough for you. Or you may love the data redundancy of RAID-61 but you may not willing to give up the performance or, perhaps more importantly, you may not be willing to have such low storage efficiency (especially if this is for your home system).&lt;br /&gt;
&lt;br /&gt;
But just choosing the RAID configuration you want is not the end of your planning. You need to also consider a number of other things. Perhaps the most important thing you need to consider is if you will need to grow/shrink the storage. The reason this is important is because you are likely to have to use LVM (Logical Volume Manager) either on top of Linux software RAID or underneath it. This forces you to carefully consider how to build both LVM and software RAID and how you expand either one or both. I would recommend walking through the expansion steps to make sure you understand how to do it (you could even pass along your ideas to someone else to have another pair of eyes examine them).&lt;br /&gt;
&lt;br /&gt;
One other thing you should consider before implementing your well formulated and thought-out RAID plan is the file system that sits on top of the storage. Based on your usage model for the storage, select one or two candidate file systems. Then do some research on each one to find out what problems or limitations exist, and also how you can optimize each file system for better performance (we’re all performance junkies at heart). There are a number of articles on the web that discuss tuning file systems with Linux software RAID.&lt;br /&gt;
&lt;br /&gt;
Assuming that you have done your careful planning (including a backup solution), let’s move on to the first “mode” of mdadm, Creating a RAID array.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Creating a RAID array&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Mdadm allows you to create a RAID array using Linux block devices. During the creation of the array, per-device superblocks are created for the RAID array (allows for the array to be assembled correctly). Using the “create” mode is the most common method for building the array and is recommended if you are just starting to use mdadm.&lt;br /&gt;
&lt;br /&gt;
The basic mdadm command for creating a RAID array is fairly simple with the following generic command and typical options.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;mdadm --create [md-device] --chunk=X --level=Y --raid-devices=Z [devices]&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where the options are as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-c, –chunk= Specify chunk size in kibibytes. The default is 64.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt; -l, –level= Set raid level, options are: linear, raid0, 0, stripe, raid1, 1, mirror, raid4, 4, raid5, 5, raid6, 6, raid10, 10, multipath, mp, faulty&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-n, –raid-devices= Specify the number of active devices in the array.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Notice that the mdadm command begins with the “–create” option that tells mdadm that it will operate in “create” mode. I like to then define the specific md-device as well but be sure you aren’t using an existing md-device name. Specifying the “chunk” option is up to you. Then you define the RAID level you want by the “–level” option with the options listed above. You can also tell mdadm how many block devices you are using with the “–raid-devices=Z” option (Z is the number of devices). Then finally you give mdadm the list of block devices you are using.&lt;br /&gt;
&lt;br /&gt;
An example of using the create option with mdadm is,&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;% mdadm --create --verbose /dev/md0 --level=0 --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
which creates a RAID-0 configuration that is labeled as /dev/md0 and uses three block devices that are /dev/sda1, /dev/sdb1, and /dev/sdc1.&lt;br /&gt;
&lt;br /&gt;
In the example, I have used the first partition of each of the three drives that are valid block devices as the block devices for mdadm. They could have easily been the entire disk such as /dev/sda or /dev/sdb. The point is that they need to be valid Linux block devices (they could even be network based devices but that’s a different discussion).&lt;br /&gt;
&lt;br /&gt;
Mdadm is smart enough to build the RAID-0 configuration using the smallest common size of each of the three devices. So it is recommended that you check on the size of each block device using fdisk as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;root@amadys-laptop:~/# /sbin/fdisk /dev/sdb&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;The number of cylinders for this disk is set to 19457.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;There is nothing wrong with that, but this is larger than 1024,&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;and could in certain setups cause problems with:&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;1) software that runs at boot time (e.g., old versions of LILO)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;2) booting and partitioning software from other OSs&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp;&amp;nbsp; (e.g., DOS FDISK, OS/2 FDISK)&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Command (m for help):&lt;/i&gt; &lt;i&gt;&lt;b&gt;p&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Disk /dev/sdb: 160.0 GB, 160041885696 bytes&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;255 heads, 63 sectors/track, 19457 cylinders&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Units = cylinders of 16065 * 512 = 8225280 bytes&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Disk identifier: 0x000bca3e&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp;&amp;nbsp; Device Boot&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Start&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Blocks&amp;nbsp;&amp;nbsp; Id&amp;nbsp; System&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;/dev/sdb1&amp;nbsp;&amp;nbsp; *&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 18704&amp;nbsp;&amp;nbsp; 150239848+&amp;nbsp; 83&amp;nbsp; Linux&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;/dev/sdb2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 18705&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19457&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6048472+&amp;nbsp;&amp;nbsp; 5&amp;nbsp; Extended&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;/dev/sdb5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 18705&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19457&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6048441&amp;nbsp;&amp;nbsp; 82&amp;nbsp; Linux swap / Solaris&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Be sure to look at the column labeled “Blocks” for the particular partition you are going to use. Do this for all the devices and make sure the number of blocks is the same or very close (otherwise you are wasting space).&lt;br /&gt;
&lt;br /&gt;
You might also notice that I used the “–verbose” option in the mdadm create command. I like to use this option to get more information about what mdadm is doing (“better informed than sorry” is a good motto). This is always a good habit to develop.&lt;br /&gt;
&lt;br /&gt;
At this point, your RAID array should be created and running. An easy way to check this is to look at /proc/mdstat.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;% cat /proc/mdstat&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fortunately, the output should be fairly easy to read at first glance. For much more detailed information you can read this article.&lt;br /&gt;
&lt;br /&gt;
Immediately after the RAID array is created it may have to go through a synchronization process. This process performs the necessary RAID functions for configuration you created. For example, for RAID-1, the blocks on the first drive are copied to the second drive even if there isn’t any information on the blocks.&lt;br /&gt;
&lt;br /&gt;
Once the array has finished synchronizing and is ready, then you can move to the next step which can be using the resulting RAID array device in LVM or creating a file system using the block device.&lt;br /&gt;
&lt;br /&gt;
There are many options that you can use in “create” mode. You can read the man pages to get a list of them but below are some of the more important ones that haven’t been presented yet in this article.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-x, –spare-devices=&amp;nbsp; &lt;/b&gt;&lt;/i&gt;This option allows you to specify spare devices in the initial array. These are devices (disks) that are used in the event that a disk in the RAID configuration fails. Mdadm then uses the spare drive immediately and starts restoring the array to the desired configuration. Mdadm also allows spare drives to be added and removed later (they don’t have to be added when the array is created). If you use spare devices be sure that the “–raid-devices” option lists the number of devices to be the actual RAID drives plus the spares.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-p, –layout=, –parity= &lt;/b&gt;&lt;/i&gt;Mdadm gives you remarkable control over your RAID configuration. This option lets you control the fine details of the data layout for RAID-5 and RAID-10 arrays and also controls the failure mode for a faulty or failed disk. Please read the manpages for more detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-z, –size= &lt;/b&gt;&lt;/i&gt;This option is the amount of space to be used from each drive in a RAID-1, RAID-4, RAID-5, or RAID-6 configuration. The size is given in kibibytes and must be a multiple of the chunk size. In addition, you must leave about 128KB (128 kibibytes) of space at the end of the drive for the RAID superblock. After the array is created you can use the “grow” mode of mdadm (–grow) to increase the size of the RAID configuration.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Assembling an mdadm RAID array&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
One of the other “modes” in mdadm is “assemble”. After your RAID array has been created using mdadm, you can stop the array using the following command:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;% mdadm --stop /dev/md0&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
which stops the RAID array /dev/md0 (be sure to unmount the file system that uses the RAID array first). However, there are problems in restarting the RAID array. When you restart the array you have to use mdadm to reassemble the array. For example,&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;% mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command assembles the parts of a previously created array into an active array and “restarts” the array (i.e. make it function). To automate this, you could put this command as part of the system startup (for example, /etc/rc.d/rc.local) and you could create a simple script for stopping and starting the array. But mdadm can do some of the leg work for you with the following command:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;% mdadm --assemble --scan&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These options allow mdadm to scan the drives and reassemble the RAID array (it looks for the RAID superblocks on the drives). Typically this is done during the init phase of the system starting. For example, on my CentOS 5.5 system, there is a line in /etc/rc.d/rc.sysinit that looks like the following.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;/sbin/mdadm -A -s&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
which will scan (“-s”) the drives and assemble (“-A”) the mdadm arrays.&lt;br /&gt;
&lt;br /&gt;
However, you can get into trouble with scanning and assembling mdadm RAID arrays when you have more than one array. What is recommended is that if you want to restart an array by hand you specify the uuid for the array (a unique “name” of the RAID array). For example,&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;% mdadm --scan --assemble --uuid=7121b438:7d36f9f6:8aa9c8b3:b5b0d211&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Since the uuid’s are unique to each array, this will ensure that mdadm can reassemble the array properly. However, mdadm‘s scanning and assembling capabilities are quite good and I routinely run two mdadm RAID configurations on my desktop and I’ve never had any confusion between which disks belong to which array (thanks to the superblocks on the devices).&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Monitoring/Following an mdadm RAID array&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The third mode of operation of mdadm is monitoring or following an mdadm RAID array. This mode monitors one or more arrays and allows action to be taken if the state of the array changes. According to the manpage for mdadm, this mode of operation is really only useful for RAID-1, 4, 5, 6, and 10, or multipath arrays since they have interesting states. On the other hand, RAID-0, and linear RAID are not useful because missing, spare, or failed drives cause these RAID modes to fail (i.e. non-operational).&lt;br /&gt;
&lt;br /&gt;
The basic option for following or monitoring mdadm controlled arrays is the following:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;mdadm --monitor options... devices...&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(Note: you can use “-F” or “–follow” in place of “–monitor”). There are several options that can be used for monitoring and following mdadm arrays as listed below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt; -m, –mail&lt;/b&gt;&lt;/i&gt; This options allows you to define an email address where mdadm alerts are sent.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-p, –program, –alert&lt;/b&gt;&lt;/i&gt; This option allows mdadm to run a “program” whenever an event is detected (it is recommended to use the full path to the program).&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-y, –syslog&lt;/b&gt;&lt;/i&gt; This option causes all events to be reported through “syslog”.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-d, –delay&lt;/b&gt;&lt;/i&gt; This options creates a delay (in seconds) from when mdadm polls the arrays to when it next polls the arrays (i.e. the interval between polling).&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-f –daemonize&lt;/b&gt;&lt;/i&gt; This options tells mdadm to run as a background daemon if it is monitoring arrays. This causes mdadm to fork and run in the child process and disconnect from the terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-i, –pid-file&lt;/b&gt;&lt;/i&gt; This option tells mdadm to write the pid of the daemon process when mdadm is run as a daemon (see previous option). The pid is written to a specified file.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-1, –oneshot&lt;/b&gt;&lt;/i&gt; This option checks the arrays only once and generates “NewArray” events as well as “DegradeArray” and “SparesMissing” events (this will show up in the logs). According to the manpages, if you run the command “mdadm –monitor –scan -1″ from a cron job, it will ensure regular notification of any degraded arrays (always a good thing).&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-t, –test&lt;/b&gt;&lt;/i&gt; This option generates a “TestMessage” alert for every array found at startup. This alert gets mailed and passed to the alert program (if you have defined one). This is very useful for testing that alert messages get through successfully (i.e. they work).&lt;br /&gt;
&lt;br /&gt;
As you can see, mdadm gives you several pretty good options for monitoring your arrays. The exact practice of how you monitor really depends upon how you want to function and any tools or processes you have developed. There are several articles on the web that show how to monitor your mdadm array.&lt;br /&gt;
&lt;br /&gt;
In the interest of helping interested people get started I will present a few tips that you can use to get started with monitoring mdadm arrays. I first recommend configuring mdadm to email you in the event of a change in state of the array. There are several articles that discuss how to do this. For example, this blog shows you how to use mdadm to send email to you in the event of a problem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to be more involved in the monitoring of your arrays there are two primary ways to get more detail: (1) &lt;i&gt;&lt;b&gt;cat /proc/mdstat&lt;/b&gt;&lt;/i&gt;, and (2) &lt;i&gt;&lt;b&gt;mdadm --detail [device]&lt;/b&gt;&lt;/i&gt;. The first option gives you a quick overview of the status of the array(s). You can parse this output (perhaps with perl or python), and create a special log or send the output to “syslog” to allow processing by syslog tools. Alternatively, you could create a simple monitoring metric that can be used in conjunction with ganglia or something similar.&lt;br /&gt;
&lt;br /&gt;
The second option gives you more detail than mdstat but again, you can parse this output and then perform some action (logs, syslog, ganglia, etc.). But the details are really up to you since you likely have specific processes or techniques for monitoring.&lt;br /&gt;
&lt;br /&gt;
One last option is to use Munin which is a monitoring tool (somewhat similar to Ganglia). It has plugins that allow you to monitor your mdadm created RAID arrays.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Building an mdadm RAID array&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Another mode of operation in mdadm is building an array but without having per-device superblocks. This means that you cannot have mdadm scan and assemble the devices into an array. Consequently, you have to be careful that you differentiate between the initial creation of the array and the assembly of the array (or you can lose data). In addition, if you built an array using build any checks that might have been done between devices are not performed. Basically, you have to be very careful when using this mode of operation and know exactly what you are doing.&lt;br /&gt;
&lt;br /&gt;
I really don’t recommend using this mode of operation so I won’t be discussing it. If you are interested in using the “build” then you can read the manpage or you can search around the Internet for references.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Growing an mdadm RAID array&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
One of the secret weapons you get with mdadm is the ability to grow, reshape, or even change RAID levels with md arrays. There are some limitations for growing and/or reshaping arrays however, just having that ability is a pretty major accomplishment for mdadm.&lt;br /&gt;
&lt;br /&gt;
The basic option for growing or reshaping md arrays is “&lt;i&gt;&lt;b&gt;-G&lt;/b&gt;&lt;/i&gt;” or “&lt;i&gt;&lt;b&gt;–grow&lt;/b&gt;&lt;/i&gt;”. There are a number of options that can be used and things can become complex fairly quickly so I won’t go over them in this introductory article. Please read the manpages for the options or you can Google for information about growing md arrays. However, let’s take a high-level look at what the “–grow” option can do.&lt;br /&gt;
&lt;br /&gt;
We can use the “–grow” option to add a third disk to a two-disk RAID-1 configuration or add another disk to our existing RAID-5 configuration. But we can also use the “grow” option to change RAID levels. For example, we can convert a two-disk RAID-1 md array to a two-disk RAID-5 md array. Direct from the mdadm author’s blog is the list of what changes (reshape) can be done:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * A RAID-1 array can change the number of devices or change the size of individual devices. A 2 drive RAID-1 can be converted to a 2 drive RAID-5.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * A RAID-4 can change the number of devices or the size of individual devices. It cannot be converted to RAID-5 yet (though that should be trivial to implement).&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * A RAID-5 can change the number of devices, the size of the individual devices, the chunk size and the layout. A 2 drive RAID-5 can be converted to RAID-1, and a 3 or more drive RAID-5 can be converted to RAID-6.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * A RAID-6 can change the number of devices, the size of the individual devices, the chunk size and the layout. And RAID-6 can be converted to RAID-5 by first changing the layout to be similar to RAID-5, then changing the level.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * A LINEAR array can have a device added to it which will simply increase its size.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * RAID-10 and RAID-0: These arrays cannot be reshaped at all at present.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So you can see that there is a great deal of flexibility in mdadm with respect to changing shape, RAID levels, adding devices, removing devices, etc., to md arrays.&lt;br /&gt;
&lt;br /&gt;
As I mentioned previously, the details of reshaping and changing RAID levels can get complicated. I suggest that before you use this option, you read all the literature you can. Then I would ask some experts who can tell you if your commands are correct or not. And before starting anything, I would definitely make sure you have a backup copy of the data and make sure the storage array isn’t in production.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Managing a md RAID array&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Managing a md RAID array primarily consists of managing the devices within the arrays. This can include adding, removing, or failing disks within an array.&lt;br /&gt;
&lt;br /&gt;
An easy (sort of) way to tell if you are using the manage mode, is that if you give a device before any options on the mdadm command line, or if the first option is “&lt;i&gt;&lt;b&gt;–add&lt;/b&gt;&lt;/i&gt;”, “&lt;i&gt;&lt;b&gt;–fail&lt;/b&gt;&lt;/i&gt;”, or “&lt;i&gt;&lt;b&gt;–remove&lt;/b&gt;&lt;/i&gt;”, then you are using the manage mode of mdadm. The general form of the mdadm command is,&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;mdadm device options ... devices ...&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used in manage mode are:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-a, –add [device] &lt;/b&gt;&lt;/i&gt;This option allows you to add the specified devices to the specified array while the array is running.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;–re-add [device]&lt;/b&gt;&lt;/i&gt; This options allows you to re-add a device to an array that was recently removed from the array.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt; -r, –remove [device] &lt;/b&gt;&lt;/i&gt;This option allows you to remove the specified device. But the device must not be active so it must be either failed or a spare device.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-f, –fail [device] &lt;/b&gt;&lt;/i&gt;This option marks the specified device as faulty (failed).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;–set-faulty &lt;/b&gt;&lt;/i&gt;This option is the same as -f.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can combine the options in one command but all of the commands must affect the same array.&lt;br /&gt;
&lt;br /&gt;
A simple example of the manage mode of mdadm is,&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;% /sbin/mdadm /dev/md1 --add /dev/sdc1 --fail /dev/sdb1 --remove /dev/sdb1&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this example, the array, /dev/md1 is the “target” of the mdadm command. The first option, “–add /dev/sdc1″ adds a device (/dev/sdc1) to the array. Then the option “–fail /dev/sdb1″ fails that device telling the array that the device is faulty. Finally, the third option, “–remove /dev/sdb1″ removes the device from the array at which point it can be removed from the system. Note that you need to first fail the device you intend to remove.&lt;br /&gt;
&lt;br /&gt;
One cool feature of mdadm is that if you remove a device (disk) from an array you can add it back (–re-add) to the array and mdadm will only update the changed blocks from when the disk was removed. This is the default behavior if you used superblocks in the creation of the array (i.e. you didn’t use the “build” mode).&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Misc&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This last mode of operation is sort of a catch-all for options and commands that don’t fit into the other six modes. In general this mode supports some operations on active arrays, operations on component devices, and the gathering of information about the arrays.&lt;br /&gt;
&lt;br /&gt;
The general form of the mdadm command in “misc” mode is the following.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;mdadm options ... devices ...&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that for a “misc” command, no array was defined before the options. The options for this mode are the following:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-&lt;/b&gt;&lt;b&gt;Q, –query&lt;/b&gt;&lt;/i&gt; This option examines a device to see if it is an md device and if it is a component of an md array. The information discovered by mdadm is presented in the output.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-D, –detail [md-device]&lt;/b&gt;&lt;/i&gt; This option prints out details of one or more md arrays. If you add the options “–brief” or “–scan” the amount of detail in the output is reduced but the format is amenable for /etc/mdadm.conf (an optional configuration file for mdadm).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt; -E, –examine&lt;/b&gt;&lt;/i&gt; This option prints the content of the md superblock on the device (or all devices if no device is specified). As with the “–detail” option, if you use “–brief” or “–scan” the amount of output is reduced and it is more amenable to /etc/mdadm.conf.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-X, –examine-bitmap&lt;/b&gt;&lt;/i&gt; This option reports the information about a bitmap file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-R, –run &lt;/b&gt;&lt;/i&gt;This option will start (activate) a partially built md array.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-S, –stop&lt;/b&gt;&lt;/i&gt; This option stops (deactivates) an active md array.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt; -o, –readonly &lt;/b&gt;&lt;/i&gt;This option marks the active array as read-only if it is not being currently used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt; -w, –readwrite&lt;/b&gt;&lt;/i&gt; This option marks the array as readwrite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt; –zero-superblock&lt;/b&gt;&lt;/i&gt; This option over-writes a valid md superblock in an array. This is useful when using disks (devices) from an old md array are used in a new one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&lt;b&gt;-t, –test &lt;/b&gt;&lt;/i&gt;This option, when used with the –detail option, sets the exit status of mdadm to reflect the status of md device. This can be very useful when scripting monitoring tools. It is also useful if you want start the md array yourself rather than rely on the kernel to autostart it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Of all of the “misc mode” operations the “–query”, “–detail”, and “–examine” options are the most generally used.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We’ve spent some time talking about RAID configurations, both single-level and Nested RAID configurations. In all of the discussions we’ve just mentioned that the RAID operations are handled by a “RAID controller”. There are two types of RAID controllers – hardware and software. The hardware RAID controller has a dedicated processor on an add-in card that handles all the RAID computations. In contrast, software RAID uses the system CPU for RAID computations (this includes “fakeRAID” controllers as well).&lt;br /&gt;
&lt;br /&gt;
This article is an introduction to mdadm, the management/admin tool for Linux software RAID that comes with virtually every Linux distribution. The tool is very flexible allowing for the standard RAID levels and Nested RAID configurations, including some specialized RAID-10 configurations we’ve discussed previously. You can even use it to build some “Triple Lindy” Nested-RAID configurations if you want.&lt;br /&gt;
&lt;br /&gt;
Mdadm has seven different “modes” of operation which we discussed. These modes allow you to create and start a RAID array, assemble a RAID array (useful when the system boots), follow or monitor a RAID array, build a RAID array (basically doing everything by hand – not recommended), grow a RAID array (one of the secret weapons of mdadm), manage a RAID array, and a “miscellaneous” category for functions that you may need that didn’t fall into the other categories.&lt;br /&gt;
&lt;br /&gt;
There are some really great features in mdadm that can easily be glossed over in a mad rush to build a RAID configuration. There are two big ones that I want to highlight. The first features is the set of standard monitoring tools in mdadm that give you a great starting place for watching the status of your md array including the ability to send out email alerts. Plus you can write fairly simple scripts to parse array status information which can be used in monitoring tools such as ganglia or munin.&lt;br /&gt;
&lt;br /&gt;
The second feature, which is probably the most significant, is the ability to grow and reshape md arrays. This allows you to add devices to an existing RAID array and grow the array to include the added space. However, the really cool feature is that you can use mdadm to change RAID levels without losing data. For example, you could convert a two-disk RAID-1 into a two-disk RAID-5 configuration. Then you could add disks to grow the RAID-5 configuration. Then you could convert the RAID-5 into a RAID-6 configuration. While I haven’t used this feature, this is pretty nifty if you ask me.&lt;br /&gt;
&lt;br /&gt;
Mdadm is a great tool for Linux that is easy to use and gives you a great deal of control over RAID arrays. If you are thinking about RAID on Linux, be sure to take a look at mdadm.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/5892813752997342974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2011/06/software-raid-on-linux-with-mdadm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/5892813752997342974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/5892813752997342974'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2011/06/software-raid-on-linux-with-mdadm.html' title='Software RAID on Linux with mdadm'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-7223477212454103582</id><published>2011-02-17T13:40:00.001-07:00</published><updated>2011-02-17T14:05:30.523-07:00</updated><title type='text'>Learning Awk by example: Part 3</title><content type='html'>&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Formatting output&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
While awk&#39;s print statement does do the job most of the time, sometimes more is needed. For those times, awk offers two good old friends called printf() and sprintf(). Yes, these functions, like so many other awk parts, are identical to their C counterparts. printf() will print a formatted string to stdout, while sprintf() returns a formatted string that can be assigned to a variable. If you&#39;re not familiar with printf() and sprintf(), an introductory C text will quickly get you up to speed on these two essential printing functions. You can view the printf() man page by typing &quot;man 3 printf&quot; on your Linux system.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s some sample awk sprintf() and printf() code. As you can see, everything looks almost identical to C.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;x=1&lt;br /&gt;
b=&quot;foo&quot;&lt;br /&gt;
printf(&quot;%s got a %d on the last test\n&quot;,&quot;Jim&quot;,83)&lt;br /&gt;
myout=(&quot;%s-%d&quot;,b,x)&lt;br /&gt;
print myout&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This code will print:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Jim got a 83 on the last test&lt;br /&gt;
foo-1&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;String functions&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Awk has a plethora of string functions, and that&#39;s a good thing. In awk, you really need string functions, since you can&#39;t treat a string as an array of characters as you can in other languages like C, C++, and Python. For example, if you execute the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;mystring=&quot;How are you doing today?&quot;&lt;br /&gt;
print mystring[3]&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You&#39;ll receive an error that looks something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;awk: string.gawk:59: fatal: attempt to use scalar as array&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Oh, well. While not as convenient as Python&#39;s sequence types, awk&#39;s string functions get the job done. Let&#39;s take a look at them.&lt;br /&gt;
&lt;br /&gt;
First, we have the basic length() function, which returns the length of a string. Here&#39;s how to use it:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;print length(mystring)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This code will print the value:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;24&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OK, let&#39;s keep going. The next string function is called index, and will return the position of the occurrence of a substring in another string, or it will return 0 if the string isn&#39;t found. Using mystring, we can call it this way:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;print index(mystring,&quot;you&quot;)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Awk prints:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;9&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We move on to two more easy functions, tolower() and toupper(). As you might guess, these functions will return the string with all characters converted to lowercase or uppercase respectively. Notice that tolower() and toupper() return the new string, and don&#39;t modify the original. This code:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;print tolower(mystring)&lt;br /&gt;
print toupper(mystring)&lt;br /&gt;
print mystring&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
....will produce this output:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;how are you doing today?&lt;br /&gt;
HOW ARE YOU DOING TODAY?&lt;br /&gt;
How are you doing today?&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
So far so good, but how exactly do we select a substring or even a single character from a string? That&#39;s where substr() comes in. Here&#39;s how to call substr():&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;i&gt;&lt;b&gt;mysub=substr(mystring,startpos,maxlen)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
mystring should be either a string variable or a literal string from which you&#39;d like to extract a substring. startpos should be set to the starting character position, and maxlen should contain the maximum length of the string you&#39;d like to extract. Notice that I said maximum length; if length(mystring) is shorter than startpos+maxlen, your result will be truncated. substr() won&#39;t modify the original string, but returns the substring instead. Here&#39;s an example:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;print substr(mystring,9,3)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Awk will print:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;you&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you regularly program in a language that uses array indices to access parts of a string (and who doesn&#39;t), make a mental note that substr() is your awk substitute. You&#39;ll need to use it to extract single characters and substrings; because awk is a string-based language, you&#39;ll be using it often.&lt;br /&gt;
&lt;br /&gt;
Now, we move on to some meatier functions, the first of which is called match(). match() is a lot like index(), except instead of searching for a substring like index() does, it searches for a regular expression. The match() function will return the starting position of the match, or zero if no match is found. In addition, match() will set two variables called RSTART and RLENGTH. RSTART contains the return value (the location of the first match), and RLENGTH specifies its span in characters (or -1 if no match was found). Using RSTART, RLENGTH, substr(), and a small loop, you can easily iterate through every match in your string. Here&#39;s an example match() call:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;print match(mystring,/you/), RSTART, RLENGTH&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Awk will print:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;9 9 3&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;String substitution&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now, we&#39;re going to look at a couple of string substitution functions, sub() and gsub(). These guys differ slightly from the functions we&#39;ve looked at so far in that they actually modify the original string. Here&#39;s a template that shows how to call sub():&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;sub(regexp,replstring,mystring)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
When you call sub(), it&#39;ll find the first sequence of characters in mystring that matches regexp, and it&#39;ll replace that sequence with replstring. sub() and gsub() have identical arguments; the only way they differ is that sub() will replace the first regexp match (if any), and gsub() will perform a global replace, swapping out all matches in the string. Here&#39;s an example sub() and gsub() call:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;sub(/o/,&quot;O&quot;,mystring)&lt;br /&gt;
print mystring&lt;br /&gt;
mystring=&quot;How are you doing today?&quot;&lt;br /&gt;
gsub(/o/,&quot;O&quot;,mystring)&lt;br /&gt;
print mystring&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
We had to reset mystring to its original value because the first sub() call modified mystring directly. When executed, this code will cause awk to output:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;HOw are you doing today?&lt;br /&gt;
HOw are yOu dOing tOday?&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Of course, more complex regular expressions are possible. I&#39;ll leave it up to you to test out some complicated regexps.&lt;br /&gt;
&lt;br /&gt;
We wrap up our string function coverage by introducing you to a function called split(). split()&#39;s job is to &quot;chop up&quot; a string and place the various parts into an integer-indexed array. Here&#39;s an example split() call:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;numelements=split(&quot;Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec&quot;,mymonths,&quot;,&quot;)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When calling split(), the first argument contains the literal string or string variable to be chopped. In the second argument, you should specify the name of the array that split() will stuff the chopped parts into. In the third element, specify the separator that will be used to chop the strings up. When split() returns, it&#39;ll return the number of string elements that were split. split() assigns each one to an array index starting with one, so the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;print mymonths[1],mymonths[numelements]&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
....will print:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Jan Dec&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Special string forms&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
A quick note -- when calling length(), sub(), or gsub(), you can drop the last argument and awk will apply the function call to $0 (the entire current line). To print the length of each line in a file, use this awk script:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;i&gt;&lt;b&gt;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print length() &lt;br /&gt;
}&lt;br /&gt;
&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
Financial fun&lt;br /&gt;
&lt;br /&gt;
A few weeks ago, I decided to write my own checkbook balancing program in awk. I decided that I&#39;d like to have a simple tab-delimited text file into which I can enter my most recent deposits and withdrawals. The idea was to hand this data to an awk script that would automatically add up all the amounts and tell me my balance. Here&#39;s how I decided to record all my transactions into my &quot;ASCII checkbook&quot;:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;23 Aug 2000&amp;nbsp;&amp;nbsp;&amp;nbsp; food&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&amp;nbsp;&amp;nbsp;&amp;nbsp; Jimmy&#39;s Buffet&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 30.25&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Every field in this file is separated by one or more tabs. After the date (field 1, $1), there are two fields called &quot;expense category&quot; and &quot;income category&quot;. When I&#39;m entering an expense like on the above line, I put a four-letter nickname in the exp field, and a &quot;-&quot; (blank entry) in the inc field. This signifies that this particular item is a &quot;food expense&quot; :) Here&#39;s what a deposit looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;23 Aug 2000&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; inco&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&amp;nbsp;&amp;nbsp;&amp;nbsp; Boss Man&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 2001.00&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this case, I put a &quot;-&quot; (blank) in the exp category, and put &quot;inco&quot; in the inc category. &quot;inco&quot; is my nickname for generic (paycheck-style) income. Using category nicknames allows me to generate a breakdown of my income and expenditures by category. As far as the rest of the records, all the other fields are fairly self-explanatory. The cleared? field (&quot;Y&quot; or &quot;N&quot;) records whether the transaction has been posted to my account; beyond that, there&#39;s a transaction description, and a positive dollar amount.&lt;br /&gt;
&lt;br /&gt;
The algorithm used to compute the current balance isn&#39;t too hard. Awk simply needs to read in each line, one by one. If an expense category is listed but there is no income category (it&#39;s &quot;-&quot;), then this item is a debit. If an income category is listed, but no expense category (&quot;-&quot;) is there, then the dollar amount is a credit. And, if there is both an expense and income category listed, then this amount is a &quot;category transfer&quot;; that is, the dollar amount will be subtracted from the expense category and added to the income category. Again, all these categories are virtual, but are very useful for tracking income and expenditures, as well as for budgeting. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;The code&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Time to look at the code. We&#39;ll start off with the first line, the BEGIN block and a function definition:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;balance, part 1&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;i&gt;&lt;b&gt;#!/usr/bin/env awk -f&lt;br /&gt;
BEGIN {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; FS=&quot;\t+&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; months=&quot;Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec&quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function monthdigit(mymonth) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (index(months,mymonth)+3)/4&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Adding the first &quot;#!...&quot; line to any awk script will allow it to be directly executed from the shell, provided that you &quot;chmod +x myscript&quot; first. The remaining lines define our BEGIN block, which gets executed before awk starts processing our checkbook file. We set FS (the field separator) to &quot;\t+&quot;, which tells awk that the fields will be separated by one or more tabs. In addition, we define a string called months that&#39;s used by our monthdigit() function, which appears next.&lt;br /&gt;
&lt;br /&gt;
The last three lines show you how to define your own awk function. The format is simple -- type &quot;function&quot;, then the function name, and then the parameters separated by commas, inside parentheses. After this, a &quot;{ }&quot; code block contains the code that you&#39;d like this function to execute. All functions can access global variables (like our months variable). In addition, awk provides a &quot;return&quot; statement that allows the function to return a value, and operates similarly to the &quot;return&quot; found in C, Python, and other languages. This particular function converts a month name in a 3-letter string format into its numeric equivalent. For example, this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;print monthdigit(&quot;Mar&quot;)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
....will print this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;3&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let&#39;s move on to some more functions. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Financial functions&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here are three more functions that perform the bookkeeping for us. Our main code block, which we&#39;ll see soon, will process each line of the checkbook file sequentially, calling one of these functions so that the appropriate transactions are recorded in an awk array. There are three basic kinds of transactions, credit (doincome), debit (doexpense) and transfer (dotransfer). You&#39;ll notice that all three functions accept one argument, called mybalance. mybalance is a placeholder for a two-dimensional array, which we&#39;ll pass in as an argument. Up until now, we haven&#39;t dealt with two-dimensional arrays; however, as you can see below, the syntax is quite simple. Just separate each dimension with a comma, and you&#39;re in business.&lt;br /&gt;
&lt;br /&gt;
We&#39;ll record information into &quot;mybalance&quot; as follows. The first dimension of the array ranges from 0 to 12, and specifies the month, or zero for the entire year. Our second dimension is a four-letter category, like &quot;food&quot; or &quot;inco&quot;; this is the actual category we&#39;re dealing with. So, to find the entire year&#39;s balance for the food category, you&#39;d look in mybalance[0,&quot;food&quot;]. To find June&#39;s income, you&#39;d look in mybalance[6,&quot;inco&quot;].&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;balance, part 2&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;i&gt;&lt;b&gt;function doincome(mybalance) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mybalance[curmonth,$3] += amount&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mybalance[0,$3] += amount&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function doexpense(mybalance) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mybalance[curmonth,$2] -= amount&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mybalance[0,$2] -= amount&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function dotransfer(mybalance) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mybalance[0,$2] -= amount&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mybalance[curmonth,$2] -= amount&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mybalance[0,$3] += amount&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mybalance[curmonth,$3] += amount&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
When doincome() or any of the other functions are called, we record the transaction in two places -- mybalance[0,category] and mybalance[curmonth, category], the entire year&#39;s category balance and the current month&#39;s category balance, respectively. This allows us to easily generate either an annual or monthly breakdown of income/expenditures later on.&lt;br /&gt;
&lt;br /&gt;
If you look at these functions, you&#39;ll notice that the array referenced by mybalance is passed in my reference. In addition, we also refer to several global variables: curmonth, which holds the numeric value of the month of the current record, $2 (the expense category), $3 (the income category), and amount ($7, the dollar amount). When doincome() and friends are called, all these variables have already been set correctly for the current record (line) being processed. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;The main block&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here&#39;s the main code block that contains the code that parses each line of input data. Remember, because we have set FS correctly, we can refer to the first field as $1, the second field as $2, etc. When doincome() and friends are called, the functions can access the current values of curmonth, $2, $3 and amount from inside the function. Take a look at the code and meet me on the other side for an explanation.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;balance, part 3&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; curmonth=monthdigit(substr($1,4,3))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; amount=$7&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #record all the categories encountered&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $2 != &quot;-&quot; )&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; globcat[$2]=&quot;yes&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $3 != &quot;-&quot; )&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; globcat[$3]=&quot;yes&quot;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #tally up the transaction properly&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $2 == &quot;-&quot; ) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $3 == &quot;-&quot; ) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;Error: inc and exp fields are both blank!&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; exit 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #this is income&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; doincome(balance)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $5 == &quot;Y&quot; )&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; doincome(balance2)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } else if ( $3 == &quot;-&quot; ) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #this is an expense &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; doexpense(balance)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $5 == &quot;Y&quot; ) &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; doexpense(balance2)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #this is a transfer&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; dotransfer(balance)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $5 == &quot;Y&quot; ) &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; dotransfer(balance2)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
In the main block, the first two lines set curmonth to an integer between 1 and 12, and set amount to field 7 (to make the code easier to understand). Then, we have four interesting lines, where we write values into an array called globcat. globcat, or the global categories array, is used to record all those categories encountered in the file -- &quot;inco&quot;, &quot;misc&quot;, &quot;food&quot;, &quot;util&quot;, etc. For example, if $2 == &quot;inco&quot;, we set globcat[&quot;inco&quot;] to &quot;yes&quot;. Later on, we can iterate through our list of categories with a simple &quot;for (x in globcat)&quot; loop.&lt;br /&gt;
&lt;br /&gt;
On the next twenty or so lines, we analyze fields $2 and $3, and record the transaction appropriately. If $2==&quot;-&quot; and $3!=&quot;-&quot;, we have some income, so we call doincome(). If the situation is reversed, we call doexpense(); and if both $2 and $3 contain categories, we call dotransfer(). Each time, we pass the &quot;balance&quot; array to these functions so that the appropriate data is recorded there.&lt;br /&gt;
&lt;br /&gt;
You&#39;ll also notice several lines that say &quot;if ( $5 == &quot;Y&quot; ), record that same transaction in balance2&quot;. What exactly are we doing here? You&#39;ll recall that $5 contains either a &quot;Y&quot; or a &quot;N&quot;, and records whether the transaction has been posted to the account. Because we record the transaction to balance2 only if the transaction has been posted, balance2 will contain the actual account balance, while &quot;balance&quot; will contain all transactions, whether they have been posted or not. You can use balance2 to verify your data entry (since it should match with your current account balance according to your bank), and use &quot;balance&quot; to make sure that you don&#39;t overdraw your account (since it will take into account any checks you have written that have not yet been cashed). &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Generating the report&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
After the main block repeatedly processes each input record, we now have a fairly comprehensive record of debits and credits broken down by category and by month. Now, all we need to do is define an END block that will generate a report, in this case a modest one:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;END {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; bal=0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; bal2=0&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (x in globcat) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; bal=bal+balance[0,x]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; bal2=bal2+balance2[0,x]&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Your available funds: %10.2f\n&quot;, bal)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Your account balance: %10.2f\n&quot;, bal2)&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report prints out a summary that looks something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Your available funds:&amp;nbsp;&amp;nbsp;&amp;nbsp; 1174.22&lt;br /&gt;
Your account balance:&amp;nbsp;&amp;nbsp;&amp;nbsp; 2399.33&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In our END block, we used the &quot;for (x in globcat)&quot; construct to iterate through every category, tallying up a master balance based on all the transactions recorded. We actually tally up two balances, one for available funds, and another for the account balance. To execute the program and process your own financial goodies that you&#39;ve entered into a file called &quot;mycheckbook.txt&quot;, put all the above code into a text file called &quot;balance&quot;, &quot;chmod +x balance&quot;, and then type &quot;./balance mycheckbook.txt&quot;. The balance script will then add up all your transactions and print out a two-line balance summary for you. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Upgrades&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I use a more advanced version of this program to manage my personal and business finances. My version (which I couldn&#39;t include here due to space limitations) prints out a monthly breakdown of income and expenses, including annual totals, net income and a bunch of other stuff. Even better, it outputs the data in HTML format, so that I can view it in a Web browser :) If you find this program useful, I encourage you to add these features to this script. You won&#39;t need to configure it to record any additional information; all the information you need is already in balance and balance2. Just upgrade the END block, and you&#39;re in business!&lt;br /&gt;
&lt;br /&gt;
I hope you&#39;ve enjoyed this series. For more information on awk, check out the resources listed below.&lt;br /&gt;
&lt;br /&gt;
Resources&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * Read earlier installments in the awk series: Awk by example, Part 1 and Part 2 on this blog.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * If you&#39;d like a good old-fashioned book, O&#39;Reilly&#39;s sed &amp;amp; awk, 2nd Edition is a wonderful choice.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * Be sure to check out the comp.lang.awk FAQ. It also contains lots of additional awk links.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * Patrick Hartigan&#39;s awk tutorial is packed with handy awk scripts.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/7223477212454103582/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2011/02/learning-awk-by-example-part-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/7223477212454103582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/7223477212454103582'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2011/02/learning-awk-by-example-part-3.html' title='Learning Awk by example: Part 3'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-2350738688920590557</id><published>2011-02-17T11:39:00.001-07:00</published><updated>2011-02-17T14:05:30.530-07:00</updated><title type='text'>Learning Awk by example: Part 2</title><content type='html'>&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Multi-line records&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Awk is an excellent tool for reading in and processing structured data, such as the system&#39;s /etc/passwd file. /etc/passwd is the UNIX user database, and is a colon-delimited text file, containing a lot of important information, including all existing user accounts and user IDs, among other things. In my previous article, I showed you how awk could easily parse this file. All we had to do was to set the FS (field separator) variable to &quot;:&quot;.&lt;br /&gt;
&lt;br /&gt;
By setting the FS variable correctly, awk can be configured to parse almost any kind of structured data, as long as there is one record per line. However, just setting FS won&#39;t do us any good if we want to parse a record that exists over multiple lines. In these situations, we also need to modify the RS record separator variable. The RS variable tells awk when the current record ends and a new record begins.&lt;br /&gt;
&lt;br /&gt;
As an example, let&#39;s look at how we&#39;d handle the task of processing an address list of Federal Witness Protection Program participants:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Jimmy the Weasel&lt;br /&gt;
100 Pleasant Drive&lt;br /&gt;
Edmonton, AB T6X0R5&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Big Tony&lt;br /&gt;
200 Incognito Ave.&lt;br /&gt;
Toronto, ON M3R1X6&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
Ideally, we&#39;d like awk to recognize each 3-line address as an individual record, rather than as three separate records. It would make our code a lot simpler if awk would recognize the first line of the address as the first field ($1), the street address as the second field ($2), and the city, state, and zip code as field $3. The following code will do just what we want:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;BEGIN {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; FS=&quot;\n&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RS=&quot;&quot;&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, setting FS to &quot;\n&quot; tells awk that each field appears on its own line. By setting RS to &quot;&quot;, we also tell awk that each address record is separated by a blank line. Once awk knows how the input is formatted, it can do all the parsing work for us, and the rest of the script is simple. Let&#39;s look at a complete script that will parse this address list and print out each address record on a single line, separating each field with a comma.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;BEGIN {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; FS=&quot;\n&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RS=&quot;&quot;&lt;br /&gt;
}&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print $1 &quot;, &quot; $2 &quot;, &quot; $3&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If this script is saved as address.awk, and the address data is stored in a file called address.txt, you can execute this script by typing &quot;awk -f address.awk address.txt&quot;. This code produces the following output:&lt;br /&gt;
&lt;i&gt;&lt;b&gt;&lt;br /&gt;
Jimmy the Weasel, 100 Pleasant Drive, Edmonton, AB T6X0R5&lt;br /&gt;
Big Tony, 200 Incognito Ave., Toronto, ON M3R1X6&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;
OFS and ORS&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In address.awk&#39;s print statement, you can see that awk concatenates (joins) strings that are placed next to each other on a line. We used this feature to insert a comma and a space (&quot;, &quot;) between the three address fields that appeared on the line. While this method works, it&#39;s a bit ugly looking. Rather than inserting literal &quot;, &quot; strings between our fields, we can have awk do it for us by setting a special awk variable called OFS. Take a look at this code snippet.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;print &quot;Hello&quot;, &quot;there&quot;, &quot;Jim!&quot;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The commas on this line are not part of the actual literal strings. Instead, they tell awk that &quot;Hello&quot;, &quot;there&quot;, and &quot;Jim!&quot; are separate fields, and that the OFS variable should be printed between each string. By default, awk produces the following output:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Hello there Jim!&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This shows us that by default, OFS is set to &quot; &quot;, a single space. However, we can easily redefine OFS so that awk will insert our favorite field separator. Here&#39;s a revised version of our original address.awk program that uses OFS to output those intermediate &quot;, &quot; strings:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;BEGIN {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; FS=&quot;\n&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RS=&quot;&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; OFS=&quot;, &quot;&lt;br /&gt;
}&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print $1, $2, $3&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Awk also has a special variable called ORS, called the &quot;output record separator&quot;. By setting ORS, which defaults to a newline (&quot;\n&quot;), we can control the character that&#39;s automatically printed at the end of a print statement. The default ORS value causes awk to output each new print statement on a new line. If we wanted to make the output double-spaced, we would set ORS to &quot;\n\n&quot;. Or, if we wanted records to be separated by a single space (and no newline), we would set ORS to &quot; &quot;. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Multi-line to tabbed&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s say that we wrote a script that converted our address list to a single-line per record, tab-delimited format for import into a spreadsheet. After using a slightly modified version of address.awk, it would become clear that our program only works for three-line addresses. If awk encountered the following address, the fourth line would be thrown away and not printed:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Cousin Vinnie&lt;br /&gt;
Vinnie&#39;s Auto Shop&lt;br /&gt;
300 City Alley&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Vancouver, BC D7E1K6&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To handle situations like this, it would be good if our code took the number of records per field into account, printing each one in order. Right now, the code only prints the first three fields of the address. Here&#39;s some code that does what we want:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;BEGIN { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; FS=&quot;\n&quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RS=&quot;&quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ORS=&quot;&quot; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
{&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x=1 &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( x&lt;nf )=&quot;&quot; {=&quot;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print $x &quot;\t&quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x++ &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print $NF &quot;\n&quot; &lt;br /&gt;
} &lt;/nf&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First, we set the field separator FS to &quot;\n&quot; and the record separator RS to &quot;&quot; so that awk parses the multi-line addresses correctly, as before. Then, we set the output record separator ORS to &quot;&quot;, which will cause the print statement to not output a newline at the end of each call. This means that if we want any text to start on a new line, we need to explicitly write print &quot;\n&quot;.&lt;br /&gt;
&lt;br /&gt;
In the main code block, we create a variable called x that holds the number of current field that we&#39;re processing. Initially, it&#39;s set to 1. Then, we use a while loop (an awk looping construct identical to that found in the C language) to iterate through all but the last record, printing the record and a tab character. Finally, we print the last record and a literal newline; again, since ORS is set to &quot;&quot;, print won&#39;t output newlines for us. Program output looks like this, which is exactly what we wanted:&lt;br /&gt;
&lt;br /&gt;
Our intended output. Not pretty, but tab delimited for easy import into a spreadsheet&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Jimmy the Weasel&amp;nbsp;&amp;nbsp;&amp;nbsp; 100 Pleasant Drive&amp;nbsp;&amp;nbsp;&amp;nbsp; Edmonton, AB T6X0R5&lt;br /&gt;
Big Tony&amp;nbsp;&amp;nbsp;&amp;nbsp; 200 Incognito Ave.&amp;nbsp;&amp;nbsp;&amp;nbsp; Toronto, ON M3R1X6&lt;br /&gt;
Cousin Vinnie&amp;nbsp;&amp;nbsp;&amp;nbsp; Vinnie&#39;s Auto Shop&amp;nbsp;&amp;nbsp;&amp;nbsp; 300 City Alley&amp;nbsp;&amp;nbsp;&amp;nbsp; Vancouver, BC D7E1K6&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Looping constructs&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We&#39;ve already seen awk&#39;s while loop construct, which is identical to its C counterpart. Awk also has a &quot;do...while&quot; loop that evaluates the condition at the end of the code block, rather than at the beginning like a standard while loop. It&#39;s similar to &quot;repeat...until&quot; loops that can be found in other languages. Here&#39;s an example:&lt;br /&gt;
&lt;br /&gt;
do...while example&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; count=1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; do {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;I get printed at least once no matter what&quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } while ( count != 1 )&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Because the condition is evaluated after the code block, a &quot;do...while&quot; loop, unlike a normal while loop, will always execute at least once. On the other hand, a normal while loop will never execute if its condition is false when the loop is first encountered.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;for loops&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Awk allows you to create for loops, which like while loops are identical to their C counterpart:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;for ( initial assignment; comparison; increment ) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; code block&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here&#39;s a quick example:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;for ( x = 1; x &amp;lt;= 4; x++ ) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;iteration&quot;,x&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet will print:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;iteration 1&lt;br /&gt;
iteration 2&lt;br /&gt;
iteration 3&lt;br /&gt;
iteration 4&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Arrays&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
You&#39;ll be pleased to know that awk has arrays. However, under awk, it&#39;s customary to start array indices at 1, rather than 0:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;myarray[1]=&quot;jim&quot;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;myarray[2]=456&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When awk encounters the first assignment, myarray is created and the element myarray[1] is set to &quot;jim&quot;. After the second assignment is evaluated, the array has two elements.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Iterating over arrays&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Once defined, awk has a handy mechanism to iterate over the elements of an array, as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;for ( x in myarray ) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print myarray[x]&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This code will print out every element in the array myarray. When you use this special &quot;in&quot; form of a for loop, awk will assign every existing index of myarray to x (the loop control variable) in turn, executing the loop&#39;s code block once after each assignment. While this is a very handy awk feature, it does have one drawback -- when awk cycles through the array indices, it doesn&#39;t follow any particular order. That means that there&#39;s no way for us to know whether the output of above code will be:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;jim&lt;br /&gt;
456&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;456&lt;br /&gt;
jim&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To loosely paraphrase Forrest Gump, iterating over the contents of an array is like a box of chocolates -- you never know what you&#39;re going to get. This has something to do with the &quot;stringiness&quot; of awk arrays, which we&#39;ll now take a look at. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Array index stringiness&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In the previous article, I showed you that awk actually stores numeric values in a string format. While awk performs the necessary conversions to make this work, it does open the door for some odd-looking code:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;a=&quot;1&quot;&lt;br /&gt;
b=&quot;2&quot;&lt;br /&gt;
c=a+b+3&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After this code executes, c is equal to 6. Since awk is &quot;stringy&quot;, adding strings &quot;1&quot; and &quot;2&quot; is functionally no different than adding the numbers 1 and 2. In both cases, awk will successfully perform the math. Awk&#39;s &quot;stringy&quot; nature is pretty intriguing -- you may wonder what happens if we use string indexes for arrays. For instance, take the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;myarr[&quot;1&quot;]=&quot;Mr. Whipple&quot;&lt;br /&gt;
print myarr[&quot;1&quot;]&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
As you might expect, this code will print &quot;Mr. Whipple&quot;. But how about if we drop the quotes around the second &quot;1&quot; index?&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;myarr[&quot;1&quot;]=&quot;Mr. Whipple&quot;&lt;br /&gt;
print myarr[1]&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Guessing the result of this code snippet is a bit more difficult. Does awk consider myarr[&quot;1&quot;] and myarr[1] to be two separate elements of the array, or do they refer to the same element? The answer is that they refer to the same element, and awk will print &quot;Mr. Whipple&quot;, just as in the first code snippet. Although it may seem strange, behind the scenes awk has been using string indexes for its arrays all this time!&lt;br /&gt;
&lt;br /&gt;
After learning this strange fact, some of us may be tempted to execute some wacky code that looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;myarr[&quot;name&quot;]=&quot;Mr. Whipple&quot;&lt;br /&gt;
print myarr[&quot;name&quot;]&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Not only does this code not raise an error, but it&#39;s functionally identical to our previous examples, and will print &quot;Mr. Whipple&quot; just as before! As you can see, awk doesn&#39;t limit us to using pure integer indexes; we can use string indexes if we want to, without creating any problems. Whenever we use non-integer array indices like myarr[&quot;name&quot;], we&#39;re using associative arrays. Technically, awk isn&#39;t doing anything different behind the scenes than when we use a string index (since even if you use an &quot;integer&quot; index, awk still treats it as a string). However, you should still call &#39;em associative arrays -- it sounds cool and will impress your boss. The stringy index thing will be our little secret. ;) &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Array tools&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
When it comes to arrays, awk gives us a lot of flexibility. We can use string indexes, and we aren&#39;t required to have a continuous numeric sequence of indices (for example, we can define myarr[1] and myarr[1000], but leave all other elements undefined). While all this can be very helpful, in some circumstances it can create confusion. Fortunately, awk offers a couple of handy features to help make arrays more manageable.&lt;br /&gt;
&lt;br /&gt;
First, we can delete array elements. If you want to delete element 1 of your array fooarray, type:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;delete fooarray[1]&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, if you want to see if a particular array element exists, you can use the special &quot;in&quot; boolean operator as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;if ( 1 in fooarray ) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;Ayep!&amp;nbsp; It&#39;s there.&quot;&lt;br /&gt;
} else {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;Nope!&amp;nbsp; Can&#39;t find it.&quot;&lt;br /&gt;
}&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Next time&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We&#39;ve covered a lot of ground in this article. Next time, I&#39;ll round out your awk knowledge by showing you how to use awk&#39;s math and string functions and how to create your own functions. I&#39;ll also walk you through the creation of a checkbook balancing program. Until then, I encourage you to write some of your own awk programs, and to check out the following resources.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Resources&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * Read Awk by example, Part 1 on this blog.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * If you&#39;d like a good old-fashioned book, O&#39;Reilly&#39;s sed &amp;amp; awk, 2nd Edition is a wonderful choice.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * Be sure to check out the comp.lang.awk FAQ. It also contains lots of additional awk links.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * Patrick Hartigan&#39;s awk tutorial is packed with handy awk scripts.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/2350738688920590557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2011/02/learning-awk-by-example-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/2350738688920590557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/2350738688920590557'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2011/02/learning-awk-by-example-part-2.html' title='Learning Awk by example: Part 2'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-8740948082038947203</id><published>2011-02-16T15:47:00.001-07:00</published><updated>2011-02-17T11:38:10.695-07:00</updated><title type='text'>Learning Awk by example: Part 1</title><content type='html'>&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;In defense of awk&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Sure, awk doesn&#39;t have a great name. But it is a great language. Awk is geared toward text processing and report generation, yet features many well-designed features that allow for serious programming. And, unlike some languages, awk&#39;s syntax is familiar, and borrows some of the best parts of languages like C, python, and bash (although, technically, awk was created before both python and bash). Awk is one of those languages that, once learned, will become a key part of your strategic coding arsenal.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;The first awk&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s go ahead and start playing around with awk to see how it works. At the command line, enter the following command:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk &#39;{ print }&#39; /etc/passwd &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
You should see the contents of your /etc/passwd file appear before your eyes. Now, for an explanation of what awk did. When we called awk, we specified /etc/passwd as our input file. When we executed awk, it evaluated the print command for each line in /etc/passwd, in order. All output is sent to stdout, and we get a result identical to catting /etc/passwd. Now, for an explanation of the { print } code block. In awk, curly braces are used to group blocks of code together, similar to C. Inside our block of code, we have a single print command. In awk, when a print command appears by itself, the full contents of the current line are printed.&lt;br /&gt;
&lt;br /&gt;
Here is another awk example that does exactly the same thing:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk &#39;{ print $0 }&#39; /etc/passwd &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In awk, the $0 variable represents the entire current line, so print and print $0 do exactly the same thing. If you&#39;d like, you can create an awk program that will output data totally unrelated to the input data. Here&#39;s an example:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk &#39;{ print &quot;&quot; }&#39; /etc/passwd &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Whenever you pass the &quot;&quot; string to the print command, it prints a blank line. If you test this script, you&#39;ll find that awk outputs one blank line for every line in your /etc/passwd file. Again, this is because awk executes your script for every line in the input file. Here&#39;s another example:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk &#39;{ print &quot;hiya&quot; }&#39; /etc/passwd &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running this script will fill your screen with hiya&#39;s. :)&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Multiple fields&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Awk is really good at handling text that has been broken into multiple logical fields, and allows you to effortlessly reference each individual field from inside your awk script. The following script will print out a list of all user accounts on your system:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk -F&quot;:&quot; &#39;{ print $1 }&#39; /etc/passwd &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, when we called awk, we use the -F option to specify &quot;:&quot; as the field separator. When awk processes the print $1 command, it will print out the first field that appears on each line in the input file. Here&#39;s another example:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk -F&quot;:&quot; &#39;{ print $1 $3 }&#39; /etc/passwd &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here&#39;s an excerpt of the output from this script:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;halt7 &lt;br /&gt;
operator11 &lt;br /&gt;
root0 &lt;br /&gt;
shutdown6 &lt;br /&gt;
sync5 &lt;br /&gt;
bin1 &lt;br /&gt;
....etc. &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As you can see, awk prints out the first and third fields of the /etc/passwd file, which happen to be the username and uid fields respectively. Now, while the script did work, it&#39;s not perfect -- there aren&#39;t any spaces between the two output fields! If you&#39;re used to programming in bash or python, you may have expected the print $1 $3 command to insert a space between the two fields. However, when two strings appear next to each other in an awk program, awk concatenates them without adding an intermediate space. The following command will insert a space between both fields:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk -F&quot;:&quot; &#39;{ print $1 &quot; &quot; $3 }&#39; /etc/passwd &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you call print this way, it&#39;ll concatenate $1, &quot; &quot;, and $3, creating readable output. Of course, we can also insert some text labels if needed:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk -F&quot;:&quot; &#39;{ print &quot;username: &quot; $1 &quot;\t\tuid:&quot; $3 }&#39; /etc/passwd &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will cause the output to be:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;username: halt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uid:7 &lt;br /&gt;
username: operator uid:11 &lt;br /&gt;
username: root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uid:0 &lt;br /&gt;
username: shutdown uid:6 &lt;br /&gt;
username: sync&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uid:5 &lt;br /&gt;
username: bin&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uid:1 &lt;br /&gt;
....etc. &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;External scripts&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Passing your scripts to awk as a command line argument can be very handy for small one-liners, but when it comes to complex, multi-line programs, you&#39;ll definitely want to compose your script in an external file. Awk can then be told to source this script file by passing it the -f option:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$ awk -f myscript.awk myfile.in &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Putting your scripts in their own text files also allows you to take advantage of additional awk features. For example, this multi-line script does the same thing as one of our earlier one-liners, printing out the first field of each line in /etc/passwd:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;BEGIN { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FS=&quot;:&quot; &lt;br /&gt;
} &lt;br /&gt;
{ print $1 } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The difference between these two methods has to do with how we set the field separator. In this script, the field separator is specified within the code itself (by setting the FS variable), while our previous example set FS by passing the -F&quot;:&quot; option to awk on the command line. It&#39;s generally best to set the field separator inside the script itself, simply because it means you have one less command line argument to remember to type. We&#39;ll cover the FS variable in more detail later in this article. &lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;The BEGIN and END blocks&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Normally, awk executes each block of your script&#39;s code once for each input line. However, there are many programming situations where you may need to execute initialization code before awk begins processing the text from the input file. For such situations, awk allows you to define a BEGIN block. We used a BEGIN block in the previous example. Because the BEGIN block is evaluated before awk starts processing the input file, it&#39;s an excellent place to initialize the FS (field separator) variable, print a heading, or initialize other global variables that you&#39;ll reference later in the program.&lt;br /&gt;
&lt;br /&gt;
Awk also provides another special block, called the END block. Awk executes this block after all lines in the input file have been processed. Typically, the END block is used to perform final calculations or print summaries that should appear at the end of the output stream.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Regular expressions and blocks&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Awk allows the use of regular expressions to selectively execute an individual block of code, depending on whether or not the regular expression matches the current line. Here&#39;s an example script that outputs only those lines that contain the character sequence foo:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;/foo/ { print } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Of course, you can use more complicated regular expressions. Here&#39;s a script that will print only lines that contain a floating point number:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;/[0-9]+\.[0-9]*/ { print } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Expressions and blocks&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
There are many other ways to selectively execute a block of code. We can place any kind of boolean expression before a code block to control when a particular block is executed. Awk will execute a code block only if the preceding boolean expression evaluates to true. The following example script will output the third field of all lines that have a first field equal to fred. If the first field of the current line is not equal to fred, awk will continue processing the file and will not execute the print statement for the current line:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$1 == &quot;fred&quot; { print $3 }&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Awk offers a full selection of comparison operators, including the usual &quot;==&quot;, &quot;&amp;lt;&quot;, &quot;&amp;gt;&quot;, &quot;&amp;lt;=&quot;, &quot;&amp;gt;=&quot;, and &quot;!=&quot;. In addition, awk provides the &quot;~&quot; and &quot;!~&quot; operators, which mean &quot;matches&quot; and &quot;does not match&quot;. They&#39;re used by specifying a variable on the left side of the operator, and a regular expression on the right side. Here&#39;s an example that will print only the third field on the line if the fifth field on the same line contains the character sequence root:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;$5 ~ /root/ { print $3 } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Conditional statements&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Awk also offers very nice C-like if statements. If you&#39;d like, you could rewrite the previous script using an if statement:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;{ &lt;br /&gt;
&amp;nbsp; if ( $5 ~ /root/ ) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print $3 &lt;br /&gt;
&amp;nbsp; } &lt;br /&gt;
} &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both scripts function identically. In the first example, the boolean expression is placed outside the block, while in the second example, the block is executed for every input line, and we selectively perform the print command by using an if statement. Both methods are available, and you can choose the one that best meshes with the other parts of your script.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s a more complicated example of an awk if statement. As you can see, even with complex, nested conditionals, if statements look identical to their C counterparts:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;{ &lt;br /&gt;
&amp;nbsp; if ( $1 == &quot;foo&quot; ) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $2 == &quot;foo&quot; ) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;uno&quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;one&quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&amp;nbsp; } else if ($1 == &quot;bar&quot; ) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;two&quot; &lt;br /&gt;
&amp;nbsp; } else { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;three&quot; &lt;br /&gt;
&amp;nbsp; } &lt;br /&gt;
} &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using if statements, we can also transform this code:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;! /matchme/ { print $1 $3 $4 }&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
to this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;{ &lt;br /&gt;
&amp;nbsp; if ( $0 !~ /matchme/ ) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print $1 $3 $4 &lt;br /&gt;
&amp;nbsp; } &lt;br /&gt;
} &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Both scripts will output only those lines that don&#39;t contain a matchme character sequence. Again, you can choose the method that works best for your code. They both do the same thing.&lt;br /&gt;
&lt;br /&gt;
Awk also allows the use of boolean operators &quot;||&quot; (for &quot;logical or&quot;) and &quot;&amp;amp;&amp;amp;&quot;(for &quot;logical and&quot;) to allow the creation of more complex boolean expressions:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;( $1 == &quot;foo&quot; ) &amp;amp;&amp;amp; ( $2 == &quot;bar&quot; ) { print } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example will print only those lines where field one equals foo and field two equals bar.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Numeric variables!&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So far, we&#39;ve either printed strings, the entire line, or specific fields. However, awk also allows us to perform both integer and floating point math. Using mathematical expressions, it&#39;s very easy to write a script that counts the number of blank lines in a file. Here&#39;s one that does just that:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;BEGIN { x=0 } &lt;br /&gt;
/^$/&amp;nbsp; { x=x+1 } &lt;br /&gt;
END&amp;nbsp;&amp;nbsp; { print &quot;I found &quot; x &quot; blank lines. :)&quot; } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the BEGIN block, we initialize our integer variable x to zero. Then, each time awk encounters a blank line, awk will execute the x=x+1 statement, incrementing x. After all the lines have been processed, the END block will execute, and awk will print out a final summary, specifying the number of blank lines it found.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Stringy variables&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
One of the neat things about awk variables is that they are &quot;simple and stringy.&quot; I consider awk variables &quot;stringy&quot; because all awk variables are stored internally as strings. At the same time, awk variables are &quot;simple&quot; because you can perform mathematical operations on a variable, and as long as it contains a valid numeric string, awk automatically takes care of the string-to-number conversion steps. To see what I mean, check out this example:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;x=&quot;1.01&quot; &lt;br /&gt;
# We just set x to contain the *string* &quot;1.01&quot; &lt;br /&gt;
x=x+1 &lt;br /&gt;
# We just added one to a *string* &lt;br /&gt;
print x &lt;br /&gt;
# Incidentally, these are comments :) &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Awk will output:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;2.01&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Interesting! Although we assigned the string value 1.01 to the variable x, we were still able to add one to it. We wouldn&#39;t be able to do this in bash or python. First of all, bash doesn&#39;t support floating point arithmetic. And, while bash has &quot;stringy&quot; variables, they aren&#39;t &quot;simple&quot;; to perform any mathematical operations, bash requires that we enclose our math in an ugly $( ) construct. If we were using python, we would have to explicitly convert our 1.01 string to a floating point value before performing any arithmetic on it. While this isn&#39;t difficult, it&#39;s still an additional step. With awk, it&#39;s all automatic, and that makes our code nice and clean. If we wanted to square and add one to the first field in each input line, we would use this script:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;{ print ($1^2)+1 } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you do a little experimenting, you&#39;ll find that if a particular variable doesn&#39;t contain a valid number, awk will treat that variable as a numerical zero when it evaluates your mathematical expression.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Lots of operators&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Another nice thing about awk is its full complement of mathematical operators. In addition to standard addition, subtraction, multiplication, and division, awk allows us to use the previously demonstrated exponent operator &quot;^&quot;, the modulo (remainder) operator &quot;%&quot;, and a bunch of other handy assignment operators borrowed from C.&lt;br /&gt;
&lt;br /&gt;
These include pre- and post-increment/decrement ( i++, --foo ), add/sub/mult/div assign operators ( a+=3, b*=2, c/=2.2, d-=6.2 ). But that&#39;s not all -- we also get handy modulo/exponent assign ops as well ( a^=2, b%=4 ).&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Field separators&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Awk has its own complement of special variables. Some of them allow you to fine-tune how awk functions, while others can be read to glean valuable information about the input. We&#39;ve already touched on one of these special variables, FS. As mentioned earlier, this variable allows you to set the character sequence that awk expects to find between fields. When we were using /etc/passwd as input, FS was set to &quot;:&quot;. While this did the trick, FS allows us even more flexibility.&lt;br /&gt;
&lt;br /&gt;
The FS value is not limited to a single character; it can also be set to a regular expression, specifying a character pattern of any length. If you&#39;re processing fields separated by one or more tabs, you&#39;ll want to set FS like so:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;FS=&quot;\t+&quot; &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, we use the special &quot;+&quot; regular expression character, which means &quot;one or more of the previous character&quot;.&lt;br /&gt;
&lt;br /&gt;
If your fields are separated by whitespace (one or more spaces or tabs), you may be tempted to set FS to the following regular expression:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;FS=&quot;[[:space:]+]&quot; &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
While this assignment will do the trick, it&#39;s not necessary. Why? Because by default, FS is set to a single space character, which awk interprets to mean &quot;one or more spaces or tabs.&quot; In this particular example, the default FS setting was exactly what you wanted in the first place!&lt;br /&gt;
&lt;br /&gt;
Complex regular expressions are no problem. Even if your records are separated by the word &quot;foo,&quot; followed by three digits, the following regular expression will allow your data to be parsed properly:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;FS=&quot;foo[0-9][0-9][0-9]&quot; &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Number of fields&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The next two variables we&#39;re going to cover are not normally intended to be written to, but are normally read and used to gain useful information about the input. The first is the NF variable, also called the &quot;number of fields&quot; variable. Awk will automatically set this variable to the number of fields in the current record. You can use the NF variable to display only certain input lines:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;NF == 3 { print &quot;this particular record has three fields: &quot; $0 } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Of course, you can also use the NF variable in conditional statements, as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;{ &lt;br /&gt;
&amp;nbsp; if ( NF &amp;gt; 2 ) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print $1 &quot; &quot; $2 &quot;:&quot; $3 &lt;br /&gt;
&amp;nbsp; } &lt;br /&gt;
} &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Record number&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The record number (NR) is another handy variable. It will always contain the number of the current record (awk counts the first record as record number 1). Up until now, we&#39;ve been dealing with input files that contain one record per line. For these situations, NR will also tell you the current line number.&amp;nbsp; NR can be used like the NF variable to print only certain lines of the input:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;(NR &amp;lt; 10 ) || (NR &amp;gt; 100) { print &quot;We are on record number 1-9 or 101+&quot; } &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;{ &lt;br /&gt;
&amp;nbsp; #skip header &lt;br /&gt;
&amp;nbsp; if ( NR &amp;gt; 10 ) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;ok, now for the real information!&quot; &lt;br /&gt;
&amp;nbsp; } &lt;br /&gt;
} &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Awk provides additional variables that can be used for a variety of purposes. We&#39;ve come to the end of our initial exploration of awk.&amp;nbsp; In the meantime, if you&#39;re eager to learn more, check out the resources listed below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Resources&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;If you&#39;d like a good old-fashioned book, O&#39;Reilly&#39;s sed &amp;amp; awk, 2nd Edition is a wonderful choice.&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Be sure to check out the comp.lang.awk FAQ. It also contains lots of additional awk links.&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Patrick Hartigan&#39;s awk tutorial is packed with handy awk scripts.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Thompson&#39;s TAWK Compiler compiles awk scripts into fast binary executables. Versions are available for Windows, and DOS.&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;The GNU Awk User&#39;s Guide is available for online reference.&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/8740948082038947203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2011/02/learning-awk-by-example-intro-to-great.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/8740948082038947203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/8740948082038947203'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2011/02/learning-awk-by-example-intro-to-great.html' title='Learning Awk by example: Part 1'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-3965505689182626137</id><published>2010-12-29T15:59:00.001-07:00</published><updated>2010-12-29T16:00:49.881-07:00</updated><title type='text'>Untangling the Power of the Linux &quot;find&quot; command</title><content type='html'>&quot;find&quot; is one of the most useful Linux/Unix tools in the toolbelt, but most people use only a fraction of its power. Many Linux/Unix questions seen online can be solved using the find command alone, getting familiar with its main functionality is one of the best things you can do for yourself in the long-term.&lt;br /&gt;
&lt;br /&gt;
find lets you do anything from finding all your .jpg files to seeing &quot;all of Michael&#39;s text documents that have the execute bit set and have been modified since yesterday.&quot; And when combined with exec or xargs, a properly constructed command can make quick work of some very heavy tasks.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Basics&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
Let&#39;s start simple by looking for things by name. Remember that the first argument you give find is where to look.&lt;br /&gt;
&lt;br /&gt;
# find all files with something in their name&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;find . -name &quot;*.jpg&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/Data/2006/Roll 20/00697_bluewaters_1440x900.jpg&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/Data/2006/Roll 20/00705_cloudyday_1440x900.jpg&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/Data/2006/Roll 20/00710_fragile_1600x1200.jpg&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/Data/2006/Roll 20/00713_coolemoticon_1440x900.jpg&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/Data/2006/Roll 20/00714_cloudyday_1440x900.jpg&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Note that by default when you give a location to start from (in our case &quot;.&quot;), the find command starts there and drills all the way down during its search. So in this case I started from my home directory and it found the files all the way down in &quot;~/Pictures/iPhoto Library/Data/2006/Roll 20&quot; as well.&lt;br /&gt;
&lt;br /&gt;
[ Placing quotes around the search criteria avoids issues with wildcard characters and is probably a good habit to get into. You can also use -iname instead of -name; it&#39;s the same but it&#39;s case insensitive ]&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Find by User&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
# find all files that belong to a certain user&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;find . -user adaniel&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/01 Intolerance.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/02 Prison Sex.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/03 Sober.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/04 Bottom.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/05 Crawl Away.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/06 Swamp Song.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/07 Undertow.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/08 4 Degrees.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/09 Flood.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;./Music/iTunes/iTunes Music/Tool/Undertow/69 Disgustipated.m4a&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
[ Also works for groups (-group) ]&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Find by Type&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;# find only directories, files, links, or sockets&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find . -type d&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Development/envelope&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Development/mhp&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Development/mservers&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Development/mservers/fortune100&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Development/mst&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Development/mst/nmap&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Development/mst/services&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Those are all directories, and to look for the others (files, links, or sockets), just substitute f, l, s for the d in the command above.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Find by Size&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;# find things over a gigabyte in size&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find ~/Movies/ -size +1024M&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;b&gt;...&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;b&gt;/Movies/Comedy/Funny.mpg&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;b&gt;/Movies/Drama/Sad.avi&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;b&gt;...&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;[ +M indicates that you&#39;re searching in megabytes, but you can also search in bytes or kilobytes if so desired. ]&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Find by Modification Time&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;find also has a number of options that help one answer forensics-oriented questions such as when a file&#39;s contents or permissions were last changed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;# find all files in /etc owned by root that have been modified within the last day&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find /etc/ -user root -mtime 1&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;/etc/passwd&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;/etc/shadow&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The checks you can use here are:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -atime: when the file was last accessed&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -ctime: when the file&#39;s permissions were last changed&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -mtime: when the file&#39;s data was last modified&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;These searches are done in 24 hour increments and followed by a number n. If you want to match the exact 24 hour period you use n by itself. More frequently, however, you&#39;ll want to say everything since yesterday, or everything &quot;more than 3 days ago.&quot; This is accomplished using the -n and +n options respectively.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;There are also minute versions of the atime, ctime, and mtime arguments:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -amin: when (in minutes) the file was last accessed&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -cmin: when (in minutes) the file&#39;s permissions were last changed&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -mmin: when (in minutes) the file&#39;s data was last modified&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Find by Permissions&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;# find all files in my directory with open permissions&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find ~ -perm 777&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;~/testfile.txt&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;~/lab.rtf&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Additional Forensics-oriented Options:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -nouser: shows output that&#39;s not associated with an existing userid&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -nogroup: shows output not associated with an existing groupid&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -links n: file has n links&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -newer file: file was modified more recently than file.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;* -perm mode: file has mode permissions.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Combinations&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Just as with any good unix/linux command, the real power comes in combining options. You can combine find arguments using and, or, and not. By default if you use two different arguments you&#39;re and&#39;ing them. If you want to use or you give the -o option, and if you want to get everything except something, you use the ! option.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;# find .jpg images (files) owned by daniel&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find . -user adaniel -type f -name *.jpg&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/autumn_woods.jpg&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/blue_forest.jpg&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/brothers.jpg&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;# now do the same, but exclude anything with &quot;autumn&quot; in the name&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find . -user adaniel -type f -name *.jpg ! -name autumn*&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/blue_forest.jpg&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;./Pictures/iPhoto Library/brothers.jpg&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;# show me all ruby programs in /apps owned by root that have been accessed in the last two minutes&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find /apps/ -user root -type f -amin -2 -name *.rb&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;/apps/testing.rb&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;/apps/runme.rb&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Combining find with exec and xargs&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;What&#39;s the fun in finding a bunch of stuff if you&#39;re not going to do something with it? So while it&#39;s interesting to say, &quot;show me stuff&quot;, it&#39;s far more useful to say, &quot;Take every text file owned by ex-employee Jason that&#39;s hasn&#39;t been accessed in 60 days and move it to a remote backup folder.&quot;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Cookbook Examples Of find in action&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Find all files on your system that are world writable. The 0002 denotes a 2 in the &quot;other&quot; field in the file permissions, which is the write bit:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find / -perm -0002&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Collect files that are not owned by valid users and delete them:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find / -nouser -print0 | xargs -0 rm&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Clean the images off of your *nix desktop:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find ~/Desktop -name &quot;*.jpg&quot; -o -name &quot;*.gif&quot; -o -name &quot;*.png&quot; -print0 | xargs -0 mv --target-directory ~/Pictures&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;** The -print0 option terminates results with a null character instead of the default newline, making it cleaner and less likely to balk in many cases&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Correct the permissions on your web directory:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find /your/webdir/ -type d -print0 | xargs -0 chmod 755&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;find /your/webdir -type f | xargs chmod 644&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Show a list of files in /etc that have been modified since last month:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;b&gt;find /etc -mtime -30&lt;/b&gt;&lt;/i&gt;&amp;nbsp;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/3965505689182626137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/12/untangling-power-of-linux-find-command.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/3965505689182626137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/3965505689182626137'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/12/untangling-power-of-linux-find-command.html' title='Untangling the Power of the Linux &quot;find&quot; command'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-1601801563018860042</id><published>2010-11-25T15:47:00.000-07:00</published><updated>2010-11-25T15:47:54.825-07:00</updated><title type='text'>25 Best SSH Commands / Tricks</title><content type='html'>&lt;span style=&quot;font-size: small;&quot;&gt;OpenSSH is a FREE version of the SSH connectivity tools that technical users of the Internet rely on. Users of telnet, rlogin, and ftp may not realize that their password is transmitted across the Internet unencrypted, but it is. OpenSSH encrypts all traffic (including passwords) to effectively eliminate eavesdropping, connection hijacking, and other attacks. Additionally, OpenSSH provides secure tunneling capabilities and several authentication methods, and supports all SSH protocol versions.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;SSH is an awesome powerful tool, there are unlimited possibility when it comes to SSH, here is the my top 25 SSH commands&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;1) Copy ssh keys to user@host to enable password-less ssh logins&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;ssh-copy-id user@host&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;To generate the keys use the command ssh-keygen&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;2) Start a tunnel from some machine’s port 80 to your local post 2001&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;ssh -N -L2001:localhost:80 somemachine&lt;/b&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Now you can acces the website by going to http://localhost:2001/&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;3) Output your microphone to a remote computer’s speaker&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;This will output the sound from your microphone port to the ssh target computer’s speaker port. The sound quality is very bad, so you will hear a lot of hissing.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt; &lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;4) Compare a remote file with a local file&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Useful for checking if there are differences between local and remote files.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;5) Mount folder/filesystem through SSH&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;sshfs name@server:/path/to/folder /path/to/mount/point&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Install SSHFS from http://fuse.sourceforge.net/sshfs.html. This will allow you to mount a folder secure over a network.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;6) SSH connection through host in the middle&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh -t reachable_host ssh unreachable_host&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Unreachable_host is unavailable from local network, but it’s available from reachable_host’s network. This command creates a connection to unreachable_host through “hidden” connection to reachable_host.&lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;7) Copy from host1 to host2, through your host&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh root@host1 “cd /somedir/tocopy/ &amp;amp;&amp;amp; tar -cf – .” | ssh root@host2 “cd /samedir/tocopyto/ &amp;amp;&amp;amp; tar -xf -”&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Good if&amp;nbsp; you &lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;only &lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;have access to host1 and host2, but they have no access to your host (so ncat won’t work) and they have no direct access to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;8) Run any GUI program remotely&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;ssh -fX &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt; &amp;lt;program&amp;gt;&lt;/program&gt;&lt;/host&gt;&lt;/user&gt;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The SSH server configuration requires:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;X11Forwarding yes # this is default in Debian&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
And it’s convenient to use:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Compression delayed&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;9) Create a persistent connection to a machine&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;ssh -MNf &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt;&lt;/host&gt;&lt;/user&gt;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
Create a persistent SSH connection to the host in the background. Combine this with settings in your &lt;i&gt;&lt;b&gt;~/.ssh/config&lt;/b&gt;&lt;/i&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Host host&lt;br /&gt;
ControlPath ~/.ssh/master-%r@%h:%p&lt;br /&gt;
ControlMaster no&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
All the SSH connections to the machine will then go through the persisten SSH socket. This is very useful if you are using SSH to synchronize files (using rsync/sftp/cvs/svn) on a regular basis because it won’t create a new socket each time to open an ssh connection.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;10) Attach screen over ssh&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh -t remote_host screen -r&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Directly attach a remote screen session (saves a useless parent bash process)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;11) Port Knocking!&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;knock &amp;lt;host&amp;gt; 3000 4000 5000 &amp;amp;&amp;amp; ssh -p &amp;lt;port&amp;gt; user@host &amp;amp;&amp;amp; knock &amp;lt;host&amp;gt; 5000 4000 3000&lt;/host&gt;&lt;/port&gt;&lt;/host&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Knock on ports to open a port to a service (ssh for example) and knock again to close the port. You have to install knockd.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
See example config file below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;[options]&lt;br /&gt;
logfile = /var/log/knockd.log&lt;br /&gt;
[openSSH]&lt;br /&gt;
sequence = 3000,4000,5000&lt;br /&gt;
seq_timeout = 5&lt;br /&gt;
command = /sbin/iptables -A INPUT -i eth0 -s %IP% -p tcp –dport 22 -j ACCEPT&lt;br /&gt;
tcpflags = syn&lt;br /&gt;
[closeSSH]&lt;br /&gt;
sequence = 5000,4000,3000&lt;br /&gt;
seq_timeout = 5&lt;br /&gt;
command = /sbin/iptables -D INPUT -i eth0 -s %IP% -p tcp –dport 22 -j ACCEPT&lt;br /&gt;
tcpflags = syn&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;12) Remove a line in a text file. Useful to fix&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh-keygen -R &amp;lt;the_offending_host&amp;gt;&lt;/the_offending_host&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
In this case it’s better do to use the dedicated tool&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;13) Run complex remote shell cmds over ssh, without escaping quotes&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;ssh host -l user $(&amp;lt;cmd.txt)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Much simpler method. More portable version: &lt;i&gt;&lt;b&gt;ssh host -l user “`cat cmd.txt`”&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;i&gt;&lt;b&gt;14) Copy a MySQL Database to a new Server via SSH with one command&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;mysqldump –add-drop-table –extended-insert –force –log-error=error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost “mysql -uUSER -pPASS NEW_DB_NAME”&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Dumps a MySQL database over a compressed SSH tunnel and uses it as input to mysql – i think that is the fastest and best way to migrate a DB to a new server!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;15) Remove a line in a text file. Useful to fix “ssh host key change” warnings&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;sed -i 8d ~/.ssh/known_hosts&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;16) Copy your ssh public key to a server from a machine that doesn’t have ssh-copy-id&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;cat ~/.ssh/id_rsa.pub | ssh user@machine “mkdir ~/.ssh; cat &amp;gt;&amp;gt; ~/.ssh/authorized_keys”&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
If you use Mac OS X or some other *nix variant that doesn’t come with ssh-copy-id, this one-liner will allow you to add your public key to a remote machine so you can subsequently ssh to that machine without a password.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;17) Live ssh network throughput test&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;yes | pv | ssh $host “cat &amp;gt; /dev/null”&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
connects to host via ssh and displays the live transfer speed, directing all transferred data to /dev/null&lt;br /&gt;
needs pv installed&lt;br /&gt;
Debian: ‘&lt;i&gt;&lt;b&gt;apt-get install pv&lt;/b&gt;&lt;/i&gt;’&lt;br /&gt;
Fedora: ‘&lt;i&gt;&lt;b&gt;yum install pv&lt;/b&gt;&lt;/i&gt;’ (may need the ‘extras’ repository enabled)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;18) How to establish a remote Gnu screen session that you can re-connect to&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh -t user@some.domain.com /usr/bin/screen -xRR&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Long before tabbed terminals existed, people have been using Gnu screen to open many shells in a single text terminal. Combined with ssh, it gives you the ability to have many open shells with a single remote connection using the above options. If you detach with “Ctrl-a d” or if the ssh session is accidentally terminated, all processes running in your remote shells remain undisturbed, ready for you to reconnect. Other useful screen commands are “Ctrl-a c” (open new shell) and “Ctrl-a a” (alternate between shells). Read this quick reference for more screen commands: &lt;a href=&quot;http://aperiodic.net/screen/quick_reference&quot;&gt;http://aperiodic.net/screen/quick_reference&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;19) Resume scp of a big file&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;rsync –partial –progress –rsh=ssh $file_source $user@$host:$destination_file&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
It can resume a failed secure copy ( usefull when you transfer big files like db dumps through vpn ) using rsync.&lt;br /&gt;
It requires rsync installed in both hosts.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;rsync –partial –progress –rsh=ssh $file_source $user@$host:$destination_file local -&amp;gt; remote&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
or&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;rsync –partial –progress –rsh=ssh $user@$host:$remote_file $destination_file remote -&amp;gt; local&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;20) Analyze traffic remotely over ssh w/ wireshark&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh root@server.com ‘tshark -f “port !22″ -w -’ | wireshark -k -i -&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This captures traffic on a remote machine with tshark, sends the raw pcap data over the ssh link, and displays it in wireshark. Hitting ctrl+C will stop the capture and unfortunately close your wireshark window. This can be worked-around by passing &lt;b&gt;-c #&lt;/b&gt; to tshark to only capture a certain # of packets, or redirecting the data through a named pipe rather than piping directly from ssh to wireshark. I recommend filtering as much as you can in the tshark command to conserve bandwidth. tshark can be replaced with tcpdump thusly:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh root@example.com tcpdump -w – ‘port !22′ | wireshark -k -i -&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;21) Have an ssh session open forever&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;autossh -M50000 -t server.example.com ‘screen -raAd mysession’&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Open a ssh session opened forever, great on laptops losing Internet connectivity when switching WIFI spots.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;22) Harder, Faster, Stronger SSH clients&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh -4 -C -c blowfish-cbc&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
We force IPv4, compress the stream, specify the cypher stream to be Blowfish. I suppose you could use aes256-ctr as well for cypher spec. I’m of course leaving out things like master control sessions and such as that may not be available on your shell although that would speed things up as well.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;23) Throttle bandwidth with cstream&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;tar -cj /backup | cstream -t 777k | ssh host ‘tar -xj -C /backup’&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
this bzips a folder and transfers it over the network to “host” at 777k bit/s.&lt;br /&gt;
cstream can do a lot more, have a look &lt;a href=&quot;http://www.cons.org/cracauer/cstream.html#usage&quot;&gt;http://www.cons.org/cracauer/cstream.html#usage&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
for example:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;echo w00t, i’m 733+ | cstream -b1 -t2&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;i&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;24) Transfer SSH public key to another machine in one step&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;&lt;br /&gt;
ssh-keygen; ssh-copy-id user@host; ssh user@host&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This command sequence allows simple setup of (gasp!) password-less SSH logins. Be careful, as if you already have an SSH keypair in your &lt;i&gt;&lt;b&gt;~/.ssh&lt;/b&gt;&lt;/i&gt; directory on the local machine, there is a possibility ssh-keygen may overwrite them. &lt;i&gt;&lt;b&gt;ssh-copy-id &lt;/b&gt;&lt;/i&gt;copies the public key to the remote host and appends it to the remote account’s &lt;i&gt;&lt;b&gt;~/.ssh/authorized_keys&lt;/b&gt;&lt;/i&gt; file. When trying ssh, if you used no passphrase for your key, the remote shell appears soon after invoking &lt;i&gt;&lt;b&gt;ssh user@host&lt;/b&gt;&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;25) Copy stdin to your X11 buffer&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;ssh user@host cat /path/to/some/file | xclip&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Have you ever had to scp a file to your work machine in order to copy its contents to a mail? xclip can help you with that. It copies its stdin to the X11 buffer, so all you have to do is middle-click to paste the content of that looong file :)&lt;br /&gt;
&lt;br /&gt;
Have Fun&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/1601801563018860042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/11/25-best-ssh-commands-tricks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/1601801563018860042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/1601801563018860042'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/11/25-best-ssh-commands-tricks.html' title='25 Best SSH Commands / Tricks'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-6340572500874470053</id><published>2010-10-27T17:38:00.000-06:00</published><updated>2010-10-27T17:38:50.412-06:00</updated><title type='text'>Managing Samba (Part 6 of 6): Remote GUI tools</title><content type='html'>While there are many tasks that can be performed from a command line, we no longer live in the Dark Ages, back when there were no graphical user interfaces (GUIs). There are graphical tools that can be used to manage Samba across a large corporate network. This tip addresses that subject. Are you ready?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Where eagles soar&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Explore remote management options, and you&#39;ll find that neither free nor commercial Windows network management tools suit all IT shops&#39; needs. There are no silver bullets. If your goal is to find a universal network management tool that will permit you to meet all site needs, no matter what, the news is not too bright.&lt;br /&gt;
&lt;br /&gt;
While your thoughts may have been to soar with the eagles, you may have to content yourself with a more mundane solution. On the other hand, if your objective is to find a tool that may save a little hassle and make it possible for you to delegate some tasks to departmental managers, there is some good news.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Basic management tools&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Samba PDC (primary domain controller) configuration that was used in the last tip is rather simple. It uses the &lt;b&gt;&lt;i&gt;tdbsam&lt;/i&gt;&lt;/b&gt; binary database in which to store the &lt;b&gt;&lt;i&gt;SambaSAMAccount&lt;/i&gt;&lt;/b&gt; information.&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;&lt;i&gt;tdbsam passdb backend&lt;/i&gt;&lt;/b&gt; is unsuitable for use with a backup domain controller (BDC). Unix user and group accounts must be resolvable either from the &lt;b&gt;&lt;i&gt;/etc/passwd&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;/etc/group&lt;/i&gt;&lt;/b&gt; system account files or via the name service switcher (NSS) facility.&lt;br /&gt;
&lt;br /&gt;
The fact that &lt;b&gt;&lt;i&gt;tdbsam&lt;/i&gt;&lt;/b&gt; does not permit operation of the PDC with a BDC means that this back end is limited to those sites that either have few users or many potential users at one location. The largest site I know that uses the &lt;b&gt;&lt;i&gt;tdbsam&lt;/i&gt;&lt;/b&gt; back end has 4,500 users. This back end can be used where the network is multi-segmented, but then fast WAN bandwidth is essential; otherwise, the infrastructure would collapse as a result of network logon failures.&lt;br /&gt;
&lt;br /&gt;
With these provisos out of the way, let&#39;s consider remote network administration needs. Where this type of network configuration is in use, the most likely need is to permit delegation of the ability to join workstations to the network as well as user and group accounts. If care and attention is given to the design of file storage layout, it may not be necessary for departmental or divisional managers to create, delete or change share configurations.&lt;br /&gt;
&lt;br /&gt;
In this situation, the Windows NT4 Domain User Manager will most likely be a sufficient tool for remote network management of users and groups. The NT4 Domain Server Manager, or the MMC Computer Management Console, could be used to administer shares and computers.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;The NT4 Domain User Manager&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In Figure 1, the Domain User Manager could be used to make Alex Monteiro a member of an additional group. It can also be used to change the primary group he belongs to. This is an example of a user account change.&lt;br /&gt;
&lt;br /&gt;
Figure 1: Changing group membership&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvin3rAemyW7iScbYr5Nk3w8gRlQ4FjSD8COOeoioj-KW48wI1C1J5NBAvVju6YalrYqrUzv7970jpvP2p94oB58tnBw_Pu5ZW5pXVE3eY95CovFXRUzHomfVkwowhSK11Xqqcjpo8c8nh/s1600/mscw_fig_03.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;332&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvin3rAemyW7iScbYr5Nk3w8gRlQ4FjSD8COOeoioj-KW48wI1C1J5NBAvVju6YalrYqrUzv7970jpvP2p94oB58tnBw_Pu5ZW5pXVE3eY95CovFXRUzHomfVkwowhSK11Xqqcjpo8c8nh/s400/mscw_fig_03.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Figure 2 demonstrates the ability, using the NT4 Domain User Manager, to change the users who are members of a particular group.&lt;br /&gt;
&lt;br /&gt;
Figure 2: Manipulation of group membership&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnKSEicFiICql4Tax2bRBgvWifALeXoQ4gdWp3s5-JimpUMRX4mEFUgcrINP6Oo7g6SCvtaScaPCJ60EBSUpv9ffmDiGm-kBBb9R9PuwarxNYowLBFzlyOwcyfwHDAiyBYibs5lvMgXdJw/s1600/mscw_fig_04.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;332&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnKSEicFiICql4Tax2bRBgvWifALeXoQ4gdWp3s5-JimpUMRX4mEFUgcrINP6Oo7g6SCvtaScaPCJ60EBSUpv9ffmDiGm-kBBb9R9PuwarxNYowLBFzlyOwcyfwHDAiyBYibs5lvMgXdJw/s400/mscw_fig_04.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
It is increasingly necessary to limit user network access times and days. Figure 3 illustrates the capability to do this using the Windows NT4 Domain User Manager. This screen is accessed by clicking on the user account that must be managed.&lt;br /&gt;
&lt;br /&gt;
Figure 3: Setting network access time limits&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiK_vDfaaPwX3XeMiZMYkKEUIiysds5G5ZlZA8rLx8O2HgJ_IiDh8e7rIkHKbOHnWrnMt1MZoL1elgt_hTXQASpnZvbgUVjlMMcDo72lRAp573TnC1fHsHmks9WoOATq7jjWMjbVJ4i1Yy/s1600/mscw_fig_05.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;332&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiK_vDfaaPwX3XeMiZMYkKEUIiysds5G5ZlZA8rLx8O2HgJ_IiDh8e7rIkHKbOHnWrnMt1MZoL1elgt_hTXQASpnZvbgUVjlMMcDo72lRAp573TnC1fHsHmks9WoOATq7jjWMjbVJ4i1Yy/s400/mscw_fig_05.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Domain access policies can also be set using the NT4 Domain User Manager. An example of policy setting is shown in Figure 4.&lt;br /&gt;
&lt;br /&gt;
Figure 4: Domain access policy setting&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKjD4eyxBcaMwImlywrAX2NcPqxuodTSRzf2ND4BP8MilS1GSlAfDYcNAgnfjK5d2xFM5Pqpd-ONziB5GdpdRbv1hPcDhrTlTCCIAZavEDxUEIZ5lERV6NYGDgo4YFTW_SDe4Uw2d1OWbX/s1600/mscw_fig_06.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;396&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKjD4eyxBcaMwImlywrAX2NcPqxuodTSRzf2ND4BP8MilS1GSlAfDYcNAgnfjK5d2xFM5Pqpd-ONziB5GdpdRbv1hPcDhrTlTCCIAZavEDxUEIZ5lERV6NYGDgo4YFTW_SDe4Uw2d1OWbX/s400/mscw_fig_06.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Using the NT4 Domain Server Manager&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The NT4 Domain Server Manager can be used to manage domain computer accounts, access controls on shares (share level ACLs) and to create shares. The example shown in Figure 5 demonstrates the settings of share level ACLs. In NT4, this is referred to as the setting of Share Permissions. The Share Permissions configuration acts as a filter that controls who can connect to the share. This ACL information is stored in the Samba file &lt;b&gt;&lt;i&gt;/var/lib/samba/share_info.tdb&lt;/i&gt;&lt;/b&gt;; it is not set in the &lt;b&gt;&lt;i&gt;smb.conf &lt;/i&gt;&lt;/b&gt;file.&lt;br /&gt;
&lt;br /&gt;
Figure 5: Managing Share Permissions (ACLs)&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmcFFSmE6ChKEW63CSbmVttoHsLrAQCE9zAJi3XzD0s9dTfwZ-NzYL-Y1UYP2-2aBu30H-sO9Z9VeqiF1zw7mSMhFaMnmxmGb3QyfiEClWRTU3Tt380o0W1GsYgoMwCp6L9CTxNieiyTks/s1600/mscw_fig_07.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;250&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmcFFSmE6ChKEW63CSbmVttoHsLrAQCE9zAJi3XzD0s9dTfwZ-NzYL-Y1UYP2-2aBu30H-sO9Z9VeqiF1zw7mSMhFaMnmxmGb3QyfiEClWRTU3Tt380o0W1GsYgoMwCp6L9CTxNieiyTks/s400/mscw_fig_07.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
A share can also be created using this tool. For that operation to work, the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file must define the script that should be called to add, change or delete a share. Example scripts are provided in the Samba source code tarball in the &lt;b&gt;&lt;i&gt;examples/scripts/share&lt;/i&gt;&lt;/b&gt; directory.&lt;br /&gt;
&lt;br /&gt;
Figure 6 demonstrates the use of the NT4 Server Manager tool to create a new share. The example scripts that are included with Samba-3 DO NOT automatically create the new directory; that is a responsibility the administrator must take care of either before or after creating the share.&lt;br /&gt;
&lt;br /&gt;
Figure 6: Adding a new share&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAtTQMaXFEr9NYdgiNObkpzPwkcrIpQE9h6snyhRp7dce7IYhCovhXlL8ZBvbM1Io5dfJt7TqgXOMLzEbyRjv7YGVzSTUDZZbA-AwCt82PDJfDQupRihsIaMeMWnHTntUb0qKmAaUuwpmy/s1600/mscw_fig_08.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;281&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAtTQMaXFEr9NYdgiNObkpzPwkcrIpQE9h6snyhRp7dce7IYhCovhXlL8ZBvbM1Io5dfJt7TqgXOMLzEbyRjv7YGVzSTUDZZbA-AwCt82PDJfDQupRihsIaMeMWnHTntUb0qKmAaUuwpmy/s400/mscw_fig_08.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;The Windows XP MMC Computer Management Console&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Windows 2000/XP Professional MMC Computer Management Console can be used to manage share level ACLs as well as file system permission settings. This use of this tool to create a new share is shown in Figure 7.&lt;br /&gt;
&lt;br /&gt;
Figure 7: Use of the MMC Console to create a new share&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxCWzaOGvbrPApu-3O4kcmcxTwOC5EkIXvJeQWRG3uhcCtlXPHFsRHT2XL85fL4BTMauJfB-JHLgH19EXdU7X7CFJiHj24bgrkR5pXeb4vs-oU2GGAgz0k09YS8gGtr0HPy3JEjTfCbWNp/s1600/mscw_fig_09.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;223&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxCWzaOGvbrPApu-3O4kcmcxTwOC5EkIXvJeQWRG3uhcCtlXPHFsRHT2XL85fL4BTMauJfB-JHLgH19EXdU7X7CFJiHj24bgrkR5pXeb4vs-oU2GGAgz0k09YS8gGtr0HPy3JEjTfCbWNp/s400/mscw_fig_09.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
In Figures 6 and 7, it should be noted that the Samba UNIX path must be entered using Windows file system semantics. The path &lt;b&gt;&lt;i&gt;c:\data\archive\&lt;/i&gt;&lt;/b&gt; will be automatically converted to the Unix semantics &lt;b&gt;&lt;i&gt;/data/archive/&lt;/i&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
So far, it has been demonstrated that a Samba domain can be managed using the NT4 Domain User Manager and the NT4 Domain Server Manager. At this time, it is necessary to point out that these tools have their limitations when used from Windows 2000 or Windows XP Professional. That limitation is brought about because Microsoft has changed the underlying remote procedure call architecture in these products so that these tools can no longer be used to manage user rights and privileges from the later generation Windows platforms.&lt;br /&gt;
&lt;br /&gt;
The NT4 Domain Management tools can be obtained from Microsoft&#39;s Web site. Just search for SRVTOOLS.EXE, download them and execute the file in the directory in which you want them to be installed.&lt;br /&gt;
&lt;br /&gt;
There exists an equivalent tool called the &lt;b&gt;Nessus Toolkit&lt;/b&gt; that can be installed on a Windows 9x/Me client. This tool can be used to manage all settings including user rights and privileges.&lt;br /&gt;
&lt;br /&gt;
The NT4 Domain User Manager and the NT4 Domain Server Manager can be used, regardless of the passdb backend that Samba is using. However, sites that are using an LDAP directory to store and manage network users and groups will almost certainly desire an LDAP directory management tools that more succinctly manages the LDAP directory.&lt;br /&gt;
&lt;br /&gt;
Administrative tool preferences are particularly personal. I have met administrators who prefer to use Webmin to manage the Samba configuration, user and group management.&lt;br /&gt;
&lt;br /&gt;
There do not seem to be many today who make use of Samba&#39;s SWAT (Samba Web Administration Tool). SWAT was originally developed for the Samba-2 series.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;LDAP Directory Managers&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Just mentioning an LDAP directory browser is often enough to evoke a reaction. That is really just too bad, because directory browsers serve a very useful purpose, particularly for those who have a profound appreciation for the power they offer. Admittedly, not all LDAP browsers are created equally!&lt;br /&gt;
&lt;br /&gt;
You may wish to check out the full range of open source offerings, or you may simply prefer to purchase a commercial tool set; the choice is yours. The following are LDAP directory browsing tools I find useful:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Name&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Source URL&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;OS Platform &amp;nbsp; Language&lt;br /&gt;
LDAP Browser&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;http://www-unix.mcs.anl.gov/~gawor/ldap/download.html&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Any&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Java&lt;br /&gt;
LDAP Admin&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;http://ldapadmin.sourceforge.net/&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Win32&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;Native EXE&lt;br /&gt;
phpldapadmin&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;http://phpldapadmin.sourceforge.net/&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Web server&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;PHP&lt;br /&gt;
Directory Administrator&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;http://diradmin.open-it.org/&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Linux + BSD&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp;C&lt;br /&gt;
GQ&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;http://sourceforge.net/projects/gqclient&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Linux + BSD&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp;C&lt;br /&gt;
&lt;br /&gt;
Of the above, it would appear that GQ and Directory Administrator are no longer actively maintained. GQ is current in its architecture, but Directory Administrator does not fully support recent releases of OpenLDAP. The other tools are currently active projects.&lt;br /&gt;
&lt;br /&gt;
There are many other choices in LDAP directory browsers. But as useful as they are to the administrator who manages LDAP directories that span a complex array of services and purposes, the use of a more work-flow or task-oriented tool is often preferred.&lt;br /&gt;
&lt;br /&gt;
There are three tools that outshine the rest where it pertains to managing a Samba-3+ LDAP environment:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Name&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Source URL&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;OS Platform&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Language&lt;br /&gt;
LAM (LDAP Account Manager)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;http://lam.sourceforge.net/&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Web server&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;PHP&lt;br /&gt;
IMC (Idealx Management Console) &amp;nbsp; &amp;nbsp;http://imc.sourceforge.net/&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Web server&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Perl&lt;br /&gt;
&lt;br /&gt;
The LDAP Browser can be used to view and edit directory information, as is shown in Figure 8. The LDAP Browser lacks the facility to perform standard account operations without exposing information that a human resources manager or a departmental head would not need to know.&lt;br /&gt;
&lt;br /&gt;
Figure 8: LDAP Browser showing a user account&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgspjWrHiFauh5V7JWJZPq0wZzrEZmUl9AP1fnKnm24CSQ8g3rlOBmrU6kLDtgmvhuPT1ayYa0M2mxf-NxruGRUos3V6uPnAF8gGFo9OnXR2AvqkkYH54IBd2tc9vSdbmgNbAnVtH89ExTU/s1600/mscw_fig_10.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;321&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgspjWrHiFauh5V7JWJZPq0wZzrEZmUl9AP1fnKnm24CSQ8g3rlOBmrU6kLDtgmvhuPT1ayYa0M2mxf-NxruGRUos3V6uPnAF8gGFo9OnXR2AvqkkYH54IBd2tc9vSdbmgNbAnVtH89ExTU/s400/mscw_fig_10.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Compared to the LDAP Browser, the LDAP Admin tool for MS Windows skillfully bridges both worlds. It looks and feels like LDAP Browser, but has added utilities that are more task-focused. Figure 9 provides a basic overview of what this tool looks like; but in Figure 10 you can see how it adds the nice touch of removing the complexity of having to deal with specific LDAP entities when adding a user account. It has this same smart touch for all management tasks.&lt;br /&gt;
&lt;br /&gt;
Figure 9: LDAP admin basic view&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuGbvV_0drWxAl4u3k8mRW8UnmDccRqMdk-MDBSc-Ox4GXp-SwAcrdDGA_0dvBf1_xu94se7gGOoqi0UbCwb247us5InvuqOazzbqtJ1w0V7eNJxI34eCsGb6oPxFVlfPKIAfQbWY9shWV/s1600/mscw_fig_11.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;303&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuGbvV_0drWxAl4u3k8mRW8UnmDccRqMdk-MDBSc-Ox4GXp-SwAcrdDGA_0dvBf1_xu94se7gGOoqi0UbCwb247us5InvuqOazzbqtJ1w0V7eNJxI34eCsGb6oPxFVlfPKIAfQbWY9shWV/s400/mscw_fig_11.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Figure 10: LDAP admin create new user account&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1m6z296V3yG1bZDDWguXg39uDR-EyCy3i-p95b4YwMbeAg8AWDs_GTFrOxB1T3zW75TuKDL86OAKHROwXu58vRs9sDZAFtoeiwBtjsWxZX5XUd70IUKhIENbPMQoXEvD3-5CEWQ29UZyz/s1600/mscw_fig_12.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1m6z296V3yG1bZDDWguXg39uDR-EyCy3i-p95b4YwMbeAg8AWDs_GTFrOxB1T3zW75TuKDL86OAKHROwXu58vRs9sDZAFtoeiwBtjsWxZX5XUd70IUKhIENbPMQoXEvD3-5CEWQ29UZyz/s400/mscw_fig_12.gif&quot; width=&quot;335&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Although these tools look neat, they are oriented towards the more technically-competent directory administrator. There are a few tools that are designed to remove the appearance of being for the LDAP guru and that have a stronger task orientation. One example is LAM, the LDAP Account Manager. An example showing a partial list of users is given in Figure 11.&lt;br /&gt;
&lt;br /&gt;
Figure 11: LDAP account manager user list&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicwXaQkyon-PL3s79nxoctftyDIrUoX06owSxWQ_uvD7_PbxpmUi19d7NbR7tNbOYFyh0EFM0EtU9rKPpfE_aI6i51YEfibYQDyoYcFor0Thj4i7JaRpxy0XcLyLxW7x6QqRdrKWiL3H9S/s1600/mscw_fig_01.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;275&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicwXaQkyon-PL3s79nxoctftyDIrUoX06owSxWQ_uvD7_PbxpmUi19d7NbR7tNbOYFyh0EFM0EtU9rKPpfE_aI6i51YEfibYQDyoYcFor0Thj4i7JaRpxy0XcLyLxW7x6QqRdrKWiL3H9S/s400/mscw_fig_01.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
On the other hand, if you are using Samba-3 + LDAP, and have chosen to use the Idealx smbldap, Perl-based scripts, to permit Samba to interface to with the LDAP directory, you may choose to use the Idealx Management Console with the SambaConsole plug-in. Figure 12 presents a typical IMC console.&lt;br /&gt;
&lt;br /&gt;
Figure 12: IMC user account console&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjWwpa6bDNdZdKmy9NePt4xttCQwg67WopuBzDJJovBycLwK-Os2M3nHRnNMGmbKdlOuYD_9YOU5Mdw2UoGp5mOZghYbTinF6w44xBGQohoRPXINKabUjAoqIIvge2OZdvoF1arXFH9OWj/s1600/mscw_fig_02.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;201&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjWwpa6bDNdZdKmy9NePt4xttCQwg67WopuBzDJJovBycLwK-Os2M3nHRnNMGmbKdlOuYD_9YOU5Mdw2UoGp5mOZghYbTinF6w44xBGQohoRPXINKabUjAoqIIvge2OZdvoF1arXFH9OWj/s400/mscw_fig_02.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Commercial utilities&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
It is good to see the number of companies that are providing tools and utilities to ease and facilitate the deployment and management of Samba-3. If your interest is in finding commercially-supported and/or commercial tools, check the Samba Website&#39;s vendors section and the GUI section.&lt;br /&gt;
&lt;br /&gt;
Looking for more tools of convenience? Check out the following Web sites: QCD Interstructures; Vintela; and Centeris.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Conclusion&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
A detailed overview has been provided demonstrating how Samba-3 can form part of a fully integrated network management infrastructure. The series of articles now completed has shown how Samba-3 user and groups and Windows clients can be fully integrated. The documentation explained how security identifiers are handled across the disparate platforms, how user rights and privileges are implemented using Samba-3, the use of basic command-line management and configuration tools, how to create a basic &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file for a PDC and how it is possible to manage the whole show using some simple as well as sophisticated GUI tools. Enjoy!</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/6340572500874470053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-6-of-6-remote-gui.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6340572500874470053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6340572500874470053'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-6-of-6-remote-gui.html' title='Managing Samba (Part 6 of 6): Remote GUI tools'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvin3rAemyW7iScbYr5Nk3w8gRlQ4FjSD8COOeoioj-KW48wI1C1J5NBAvVju6YalrYqrUzv7970jpvP2p94oB58tnBw_Pu5ZW5pXVE3eY95CovFXRUzHomfVkwowhSK11Xqqcjpo8c8nh/s72-c/mscw_fig_03.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-2811906408557734760</id><published>2010-10-27T17:37:00.001-06:00</published><updated>2010-10-27T17:37:55.923-06:00</updated><title type='text'>Managing Samba (Part 5 of 6): Configuration with the net utility, part two</title><content type='html'>In part one of this Samba-3 Management tip, we prepared for the big act. Now, the excitement begins. We&#39;re ready to use the net utility in the final steps in configuration of the primary domain controller.&lt;br /&gt;
&lt;br /&gt;
Up to this point, no user account has been granted Windows network administrative rights and privileges. Our objective is to give the account &lt;b&gt;&lt;i&gt;mstone&lt;/i&gt;&lt;/b&gt; full administrative rights. This is simply achieved by making &lt;b&gt;&lt;i&gt;mstone&lt;/i&gt;&lt;/b&gt; a member of the Linux managersgroup. The managers group is mapped to the Windows Domain Admins group. However, life is not that simple. By default, the Domain Admin group has not rights other than to assign rights and privileges. This means that specific privileges must be assigned even to the Domain Admins group.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Create an administrative user account&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s verify that &lt;b&gt;&lt;i&gt;mstone&lt;/i&gt;&lt;/b&gt; is a member of the managers group within the Linux environment:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; id mstone&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;uid=1001(mstone) gid=100(users) groups=100(users),1001(managers)&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Now we must demonstrate that within Samba &lt;b&gt;&lt;i&gt;mstone&lt;/i&gt;&lt;/b&gt; is a member of the Domain Admins group:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc group members &quot;Domain Admins&quot; -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ROSESARERED\mstone&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Good, &lt;b&gt;&lt;i&gt;mstone&lt;/i&gt;&lt;/b&gt; is a member of the Windows Domain Admins group. This is achieved by way of the mapping we established by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net groupmap modify ntgroup=&quot;Domain Admins&quot; unixgroup=managers&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Assign rights and privileges to the domain admins group&lt;br /&gt;
&lt;br /&gt;
In this step, the Domain Admins group is assigned (given, or granted) all administrative rights:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc rights grant &quot;Domain Admins&quot; \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeMachineAccountPrivilege \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeTakeOwnershipPrivilege \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeBackupPrivilege \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeRestorePrivilege \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeRemoteShutdownPrivilege \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SePrintOperatorPrivilege \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeAddUsersPrivilege \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeDiskOperatorPrivilege -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Successfully granted rights.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Make the PDC a domain member&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The next step is to make our PDC a member of its own domain. This step requires domain administrative privilege which &lt;b&gt;&lt;i&gt;mstone&lt;/i&gt;&lt;/b&gt; has. Execute the following:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc join -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Joined domain ROSESARERED&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
It is a good practice to validate every step, as we have done so far. The domain trust account that was created by joining the domain can appear to proceed correctly, but it may not work. This can be checked simply by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc testjoin&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Join to &#39;ROSESARERED&#39; is OK&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Let&#39;s run a further check to see obtain the status of the domain environment:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc info -S violetsblue&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Domain Name: ROSESARERED&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Domain SID: S-1-5-21-3169455399-2908770435-3209857667&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Sequence number: 1135058837&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Num users: 2&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Num domain groups: 4&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Num local groups: 0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
So far, so good!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Create additional users&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So far, the net command has been used to:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;map Linux groups to Windows groups;&lt;/li&gt;
&lt;li&gt;check Windows group membership;&lt;/li&gt;
&lt;li&gt;join the PDC to its own domain;&lt;/li&gt;
&lt;li&gt;validate the domain account (join); and,&lt;/li&gt;
&lt;li&gt;check domain information (note: not dependent on the join).&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
In the last step, we confirmed that there are only two Windows user accounts and four Windows group accounts.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s add accounts for the users &lt;i style=&quot;font-weight: bold;&quot;&gt;misty&lt;/i&gt;,&lt;i style=&quot;font-weight: bold;&quot;&gt; jable&lt;/i&gt;,&lt;i style=&quot;font-weight: bold;&quot;&gt; dstornton&lt;/i&gt; using the remote management net tool:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc user add misty -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc user add jable -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc user add dstornton -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
The use of the net rpc group add facility results in Samba calling the add user script to add the account to the Linux account database (&lt;b&gt;&lt;i&gt;/etc/passwd&lt;/i&gt;&lt;/b&gt;), followed by addition to the passdb backend (&lt;b&gt;&lt;i&gt;tdbsam&lt;/i&gt;&lt;/b&gt;) specified in the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, these accounts do not yet have a password. We must rectify that at once:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc password misty secretpw1 -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc password jable secretpw2 -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc password dstornton secretpw3 -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
If the password &lt;b&gt;&lt;i&gt;secretpw1&lt;/i&gt;&lt;/b&gt; is not added to the command line, this tool will prompt for the password to be entered. It looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc password misty -S violetsblue -Umstone%n3v3r2l8&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Enter new password for misty: XXXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now let&#39;s add misty to the group scientists:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc group addmem scientists misty -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
It is possible to add the other new members. We can add a new group called warriors by executing this command:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc group add warriors -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s add misty so she will be a member of the new warriors group:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc group addmem warriors misty -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To remove misty from the warriors group, just use the delmem operator, as shown here:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc group delmem warriors misty -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Assign user rights&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Often, it is necessary to give a user certain limited administrative privileges. An example is making it possible for a normal user to manage printing operations. In this case misty is assigned the printer management capabilities:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc rights grant &quot;ROSESARERED\misty&quot; SePrintOperatorPrivilege \&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;-S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Assigned rights can be examined as shown here:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; net rpc rights list accounts -S violetsblue -Umstone%n3v3r2l8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;BUILTIN\Print Operators&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;No privileges assigned&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;BUILTIN\Account Operators&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;No privileges assigned&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ROSESARERED\Domain Admins&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeMachineAccountPrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeTakeOwnershipPrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeBackupPrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeRestorePrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeRemoteShutdownPrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SePrintOperatorPrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeAddUsersPrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeDiskOperatorPrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;BUILTIN\Backup Operators&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;No privileges assigned&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;BUILTIN\Server Operators&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;No privileges assigned&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ROSESARERED\misty&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SePrintOperatorPrivilege&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;BUILTIN\Administrators&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;No privileges assigned&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Everyone&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;No privileges assigned&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Wrapping up&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The net utility permits very extensive remote management of a Samba server. So far, I have demonstrated how this tool can be used to join a Samba server to its domain, add/delete/change user and group accounts, map Linux groups to Windows groups, add users to groups, and so on. The use of this tool to assign rights and privileges has also been briefly touched upon.&lt;br /&gt;
&lt;br /&gt;
The use of this command is well documented in The Official Samba-3 HOWTO and Reference Guide in chapter 12. The latest version of this document is available from Samba.org. This document is also available from Amazon.com in hard copy under ISBN No: 0131882228.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;The series continues&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This is the fifth article in my Managing Samba series. Articles in this series have so far explained:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Windows network identity basics and their use in Samba-3;&lt;/li&gt;
&lt;li&gt;Windows NT/200x user rights and privileges in Samba 3.0.11 and later;&lt;/li&gt;
&lt;li&gt;Domain control parameters and operating system interface scripts in the Samba smb.conf file.&lt;/li&gt;
&lt;li&gt;The pdbedit utility to manage domain and user account policy settings.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
The &lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-6-of-6-remote-gui.html&quot;&gt;next article&lt;/a&gt; will deal with remote GUI management tools and facilities. It will review various GUI tools that can be used to facilitate network management. Of course, some will quickly point out that if this can be made simple enough, it should be possible to delegate many day-to-day operations to senior user staff and thus reduce the cost of keeping the network operational.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/2811906408557734760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/2811906408557734760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/2811906408557734760'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6.html' title='Managing Samba (Part 5 of 6): Configuration with the net utility, part two'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-6602276129258019206</id><published>2010-10-27T17:37:00.000-06:00</published><updated>2010-10-27T17:37:11.325-06:00</updated><title type='text'>Managing Samba (Part 5 of 6): Configuration with the net utility, part one</title><content type='html'>The net utility plays a key role in completing the configuration of a Samba-3 domain controller or activating and managing a Samba-3 domain member server.&lt;br /&gt;
&lt;br /&gt;
This tip discusses the practical use of the net command. It can be used for initial configuration as well as for on-going system maintenance of Samba-3 domain security environments. My key objective is to demonstrate the assignment and use of network administration tasks using a non-root account. This capability was first available with Samba-3.0.11 and is surely ready for prime-time use. The examples shown here provide the key to safe deployment of Samba using samba-3.0.21.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Pre-flight check&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Before launching into the use of the net utility, it is best to quickly check that you have installed a valid smb.conf.master file. A modified version of the file I used previously is shown in Figure 1. This file can be converted into the operational smb.conf file by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; testparm -s smb.conf.master &amp;gt; /etc/samba/smb.conf&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Always check the validity of the file before starting Samba. The recommended way to do this is by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; testparm&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Load smb config files from /etc/samba/smb.conf&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Processing section &quot;[homes]&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Processing section &quot;[printers]&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Processing section &quot;[netlogon]&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Processing section &quot;[profiles]&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Loaded services file OK.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Server role: ROLE_DOMAIN_PDC&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Press enter to see a dump of your service definitions&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Before starting Samba, it is a good idea to check that there are no tdb files on the system and that may be a left-over from a previous execution of the smbd and nmbd deamons.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheR7FVMIuNxeL7i3Mo5gXXS01Aiq6d8C-TWdAMUkgARnj88CcKevMifWTekyegOH7cMHXGxpAVJQ0ltronePwn3JmuhAANkWPAa9HjMP9XtPubgdwcLjq2AdXPXprC60P9dPbNOXpLeHJf/s1600/manage_samba_1.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheR7FVMIuNxeL7i3Mo5gXXS01Aiq6d8C-TWdAMUkgARnj88CcKevMifWTekyegOH7cMHXGxpAVJQ0ltronePwn3JmuhAANkWPAa9HjMP9XtPubgdwcLjq2AdXPXprC60P9dPbNOXpLeHJf/s1600/manage_samba_1.gif&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Samba-3 will create tdb files in the following directories:&lt;br /&gt;
&lt;br /&gt;
Red Hat Linux: &lt;b&gt;&lt;i&gt;/etc/samba, /var/cache/samba&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Never remove the tdb files from a working Samba server unless you really do know what you are doing. The &lt;b&gt;&lt;i&gt;/etc/samba/secrets.tdb&lt;/i&gt;&lt;/b&gt; file contains essential security data that includes the domain SID. The &lt;b&gt;&lt;i&gt;/etc/samba/passdb.tdb&lt;/i&gt;&lt;/b&gt; file contains the SambaSAMAccount information. Our example network uses the &lt;b&gt;&lt;i&gt;passdb backend = tdbsam&lt;/i&gt;&lt;/b&gt; method of storing Windows network account information.&lt;br /&gt;
&lt;br /&gt;
You can remove old Samba run-time files after first stopping the nmbd and smbd daemons by executing:&lt;br /&gt;
&lt;br /&gt;
Red Hat Linux:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; service smb stop &amp;amp;&amp;amp; service nmb stop&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; rm /etc/samba/*tdb /var/cache/samba/*&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Start the Samba smbd and nmbd daemons using the appropriate method for your Linux platform. On a Red Hat Linux execute:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root#&amp;gt; service nmb start &amp;amp;&amp;amp; service smb start&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Sites that use an LDAP directory to store all account information require more detailed configurations that are beyond the scope of this article series; however, the net command can be used in the same manner as is described below. This tool is independent of the account back end and simply calls the scripts that are specified in the &lt;b&gt;&lt;i&gt;smb.conf &lt;/i&gt;&lt;/b&gt;file for all host environment dependent operations.&lt;br /&gt;
&lt;br /&gt;
There are yet a few more things that must be completed before your start can move on. The objective of this series of tips is to end up with a working Samba domain controller. This requires the creation of user and group accounts on the PDC. There are two sides to these accounts: the Linux system account; and the SambaSAMAccount.&lt;br /&gt;
&lt;br /&gt;
The &lt;u&gt;&lt;i&gt;first article&lt;/i&gt;&lt;/u&gt; in this series described the relationship between the system account and the Windows networking accounts (or SambaSAMAccounts).&lt;br /&gt;
&lt;br /&gt;
The last tip in this series, which covered pdbedit, stepped through the account creation process. If you followed each step, your system should now have a number of Linux user and group accounts, each of which has been configured to have an equivalent Windows networking account.&lt;br /&gt;
&lt;br /&gt;
So that all steps are covered in this tip, I will briefly, and without explanation, create the accounts that are necessary for the use of the net command. The steps that are necessary for this are shown in Figure 2.&lt;br /&gt;
&lt;br /&gt;
Note: Some Linux distributions do not permit addition of a user (machine) account with the home directory specified as &lt;b&gt;&lt;i&gt;/dev/null&lt;/i&gt;&lt;/b&gt;. If your platform is one of these it will be necessary to change the add machine script parameter in the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file to use a permitted value.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm7H1-RNt7j5fDDiKD0jL5L3xtjTjymABONC1ZNEH5SYcwNXldW9fKp4gVXfczppSNJe7FU0bhoQmc4Z2vB68Ov5cqi86GM58j553R9ioQkw_E4T7o7kJ16xn_Y9uhAqcml_U8oYK3DWOk/s1600/manage_samba_2.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;492&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm7H1-RNt7j5fDDiKD0jL5L3xtjTjymABONC1ZNEH5SYcwNXldW9fKp4gVXfczppSNJe7FU0bhoQmc4Z2vB68Ov5cqi86GM58j553R9ioQkw_E4T7o7kJ16xn_Y9uhAqcml_U8oYK3DWOk/s640/manage_samba_2.gif&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
All right! You&#39;ve laid the foundation. Now, in &lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6.html&quot;&gt;part two&lt;/a&gt; of this tip, we&#39;ll get down to the final steps in configuration of the primary domain controller.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/6602276129258019206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6_26.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6602276129258019206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6602276129258019206'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6_26.html' title='Managing Samba (Part 5 of 6): Configuration with the net utility, part one'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheR7FVMIuNxeL7i3Mo5gXXS01Aiq6d8C-TWdAMUkgARnj88CcKevMifWTekyegOH7cMHXGxpAVJQ0ltronePwn3JmuhAANkWPAa9HjMP9XtPubgdwcLjq2AdXPXprC60P9dPbNOXpLeHJf/s72-c/manage_samba_1.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-1930688139480846430</id><published>2010-10-27T17:36:00.000-06:00</published><updated>2010-10-27T17:36:19.416-06:00</updated><title type='text'>Managing Samba (Part 4 of 6): The pdbedit utility, part 2</title><content type='html'>The &lt;b&gt;&lt;i&gt;pdbedit&lt;/i&gt;&lt;/b&gt; tool in Samba-3 is the only one that can manage account security and policy settings. As it was said in part one of this tip, having control of account security and policy settings is important to businesses that must comply with the Sarbanes-Oxley Act of 2002. Now, I&#39;ll show you how to put &lt;b&gt;&lt;i&gt;pdbedit&lt;/i&gt;&lt;/b&gt; to work creating Linux system user and group accounts; assembling Windows group accounts, thus mapping Windows group accounts to Linux group accounts; adding Windows user accounts; and establishing network access policies and controls.&lt;br /&gt;
&lt;br /&gt;
First, let&#39;s get on with the establishment of Linux system user and group accounts.&lt;br /&gt;
&lt;br /&gt;
Two group accounts will be created, one for scientists, and one for managers:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; groupadd scientists&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; groupadd managers&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Two user accounts will be created here: one for Tom Bryant (scientists), and one for Melinda Stone (managers). Both users require a home directory. The following steps will create these accounts:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; useradd -m -c &quot;Tom Bryant&quot; -G scientists -g users tbryant&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; passwd tbryant&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;New Password: XXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Re-enter New Password: XXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; useradd -m -c &quot;Melinda Stone&quot; -G managers -g users mstone&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; passwd mstone&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;New Password: XXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Re-enter New Password: XXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Both accounts are specifically created to be primary members of the users group, and secondary members of the respective groups to which they also belong.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Creation of Windows group accounts&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Linux group accounts must now be mapped to Windows group accounts. The following commands will map the key Windows domain groups to local Linux system accounts:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; net groupmap modify ntgroup=&quot;Domain Admins&quot; unixgroup=managers&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; net groupmap modify ntgroup=&quot;Domain Users&quot; unixgroup=users&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; net groupmap modify ntgroup=&quot;Domain Guests&quot; unixgroup=nobody&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
The next commands will create Windows groups that will match the Linux group accounts:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; net groupmap create ntgroup=&quot;Scientists&quot; unixgroup=scientists type d&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Addition of Windows user accounts&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The following steps create the &lt;b&gt;&lt;i&gt;SambaSAMAccount&lt;/i&gt;&lt;/b&gt; entries in the passdb backend that was chosen in the last article (tdbsam). The use of the &lt;b&gt;&lt;i&gt;pdbedit&lt;/i&gt;&lt;/b&gt; tool will demonstrate the account information that can be managed.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -a tbryant&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;new password: XXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;retype new password: XXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -a mstone&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;new password: XXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;retype new password: XXXXXXX&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Both accounts have now been added. This is demonstrated here:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -Lw&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;tbryant:6001:0E74DBD7B1C3CC88AAD3B435B51404EE:72BBEAA844F6E0E9CE546CE7E61C963F:[U ]:LCT-439530A0:&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;mstone:6002:744F505BEE319723AAD3B435B51404EE:5F7D844D278CD6898B4022AE766CCA1A:[U ]:LCT-43953197:&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SambaSAMAccount&lt;/i&gt;&lt;/b&gt; information can be displayed using the pdbedit tool:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -Lv tbryant&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Unix username: tbyrant&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;NT username:&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Account Flags: [U ]&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;User SID: S-1-5-21-726309263-6128913605-1168186429-13000&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Primary Group SID: S-1-5-21-726309263-6128913605-1168186429-1201&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Full Name:&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Home Directory: \\violetsblue\tbryant&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;HomeDir Drive: H:&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Logon Script: scripts\logon.bat&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Profile Path: \\violetsblue\profiles\tbryant&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Domain: ROSESARERED&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Account desc:&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Workstations:&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Munged dial:&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Logon time: 0&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Logoff time: Mon, 18 Jan 2038 20:14:07 MST&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Kickoff time: Mon, 18 Jan 2038 20:14:07 MST&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Password last set: Mon, 05 Dec 2005 23:37:11 MST&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Password can change: Wed, 07 Dec 2005 23:37:11 MST&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Password must change: Thu, 19 Jan 2006 23:37:11 MST&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Last bad password : 0&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Bad password count : 0&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The use of the tdbsam backend account database makes it possible to override any of these settings.&lt;br /&gt;
&lt;br /&gt;
Had the smbpasswd backend database been used, it would not be possible to change these settings, because this database does not store the advanced attributes of the &lt;b&gt;&lt;i&gt;SambaSAMAccount&lt;/i&gt;&lt;/b&gt; data structure.&lt;br /&gt;
&lt;br /&gt;
It is possible to set a forced password change for just one user in the following:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit --pwd-must-change-time=&quot;2006-01-31&quot; \&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;--time-format=&quot;%Y-%m-%d&quot; tbryant&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Unix username: tbryant&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;...&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Password last set: Mon, 05 Dec 2005 23:37:11 MST&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Password can change: Wed, 07 Dec 2005 23:37:11 MST&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Password must change: Tue, 31 Jan 2006 00:00:00 MST&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;...&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In many cases, it is more desirable to create a global network access policy than to be required to set each account separately. The global setting must be in place before user accounts are created, otherwise the old settings will continue to be used. The per-user settings override the global settings.&lt;br /&gt;
&lt;br /&gt;
In the following example, a global policy will be implemented. The policies that can be set include:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;min password length&lt;/li&gt;
&lt;li&gt;password history&lt;/li&gt;
&lt;li&gt;user must logon to change password&lt;/li&gt;
&lt;li&gt;maximum password age&lt;/li&gt;
&lt;li&gt;minimum password age&lt;/li&gt;
&lt;li&gt;lockout duration&lt;/li&gt;
&lt;li&gt;reset count minutes&lt;/li&gt;
&lt;li&gt;bad lockout attempt&lt;/li&gt;
&lt;li&gt;disconnect time&lt;/li&gt;
&lt;li&gt;refuse machine password change&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
In our example, &amp;nbsp;stringent Sarbanes-Oxley compliance settings will be implemented.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -P &quot;min password length&quot; -C 8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;description: Minimal password length (default: 5)&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;min password length&quot; value was: 5&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;min password length&quot; value is now: 8&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
The policy was set to eight characters. Security conscious sites may want to set this to 14 characters:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -P &quot;password history&quot; -C 5&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Length of Password History Entries (default: 0 =&amp;gt; off)&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;password history&quot; value was: 5&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;password history&quot; value is now: 5&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
In the example above, the last five passwords will be remembered. This means that an old password can be reused only after six unique passwords have already been used. We want a minimum password age of 45 days (3888000 seconds).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -P &quot;minimum password age&quot; -C 3888000&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;description: Minimal password age, in seconds (default: 0 =&amp;gt; allow immediate password change)&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;minimum password age&quot; value was: -1&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;minimum password age&quot; value is now: 3888000&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
A password can be changed only after 45 days:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -P &quot;maximum password age&quot; -C 3888000&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;maximum password age&quot; description: Maximum password age, in seconds (default: -1 =&amp;gt; never expire passwords)&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;maximum password age&quot; value was: -1&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;maximum password age&quot; value is now: 3888000&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Passwords must be changed every 45 days. This means that an old password can be re-used only after 270 days. If the minimum password age is left at the default, a smart user can simply enter six new passwords and then reset the original password in rapid succession, thereby defeating the controls.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -P &quot;bad lockout attempt&quot; -C 3&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;description: Lockout users after bad logon attempts (default: 0 =&amp;gt; off)&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;bad lockout attempt&quot; value was: 0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;account policy &quot;bad lockout attempt&quot; value is now: 3&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
The setting above ensures that the user account will be locked out after three failed logon attempts. This is an important means by which password cracking attempts may be thwarted.&lt;br /&gt;
&lt;br /&gt;
Where an LDAP password back end is used, the policy settings must be exported to the LDAP directory. This can be done by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;root #&amp;gt; pdbedit -y -i tdbsam -e ldapsam&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
It must be noted that the full capabilities mentioned in this article were stabilized in the Samba-3.0.21 release. Where Sarbanes-Oxley compliance is required please use the most recently released stable version.&lt;br /&gt;
&lt;br /&gt;
The use of the Samba &lt;b&gt;&lt;i&gt;pdbedit&lt;/i&gt;&lt;/b&gt; tool has been shown to be a simple matter. Once you have mastered it, you&#39;ll be ready to move on to the next phase of mastering Samba management: the practical use of the net command, both for initiation configuration as well as for on-going system maintenance. That&#39;s the topic of the &lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6_26.html&quot;&gt;next episode&lt;/a&gt; in the Managing Samba series.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/1930688139480846430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-4-of-6-pdbedit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/1930688139480846430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/1930688139480846430'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-4-of-6-pdbedit.html' title='Managing Samba (Part 4 of 6): The pdbedit utility, part 2'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-8012363037589432198</id><published>2010-10-27T17:35:00.000-06:00</published><updated>2010-10-27T17:35:08.380-06:00</updated><title type='text'>Managing Samba (Part 4 of 6): The pdbedit utility, part 1</title><content type='html'>Administrators who want to make the most of Samba-3 need to know their PDCs (Primary Domain Controllers) . If you&#39;re migrating from Windows to Linux, or remotely managing Samba-3, knowing how to prepare and use Samba-3 PDC is a must.&lt;br /&gt;
&lt;br /&gt;
Remote management of Samba is easily enabled by use of appropriate configuration settings. To achieve proper usage, you have to prepare the Samba-3 PDC for use. This article discusses the first steps, those that involve the &lt;b&gt;&lt;i&gt;pdbedit&lt;/i&gt;&lt;/b&gt; command. Detailed examples will be provided to demonstrate how this tool can be used to set password expiration limits, reconfigure the location of a users home folder, the location of the users roaming profile, and so on.&lt;br /&gt;
&lt;br /&gt;
Additionally, the article will explain how to disable roaming profiles for all or some users, and will provide guidelines for Microsoft (MS) Windows workstation configuration to bring sanity to network management.&lt;br /&gt;
&lt;br /&gt;
Before we get started, let us consider again some key facts regarding the way the Samba integrates with the server operating system that is hosting it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Samba interaction with the host operating system&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
A few simple facts must be stated. There are many postings to the Samba mailing lists in which the author is perplexed that certain commands have failed to produce the behavior that was expected.&lt;br /&gt;
&lt;br /&gt;
Samba implements MS Windows file and print services without overriding Linux system security. What does this mean? It means that:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;MS Windows users and groups must map to local operating system UIDs and GIDs.&lt;/li&gt;
&lt;li&gt;Therefore, Samba does not create Linux (POSIX) user and group accounts, but passes this responsibility off to interface scripts.&lt;/li&gt;
&lt;li&gt;All file system access is limited by the normal Linux security constraints that apply to the mapped UID/GID information. Where in the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file share stanza parameters are specified to force a particular action. For example: force user, force group, force create mode, etc. Basic Linux file system access controls remain in effect.&lt;/li&gt;
&lt;li&gt;Samba tools and utilities do not interfere with Linux system administration. The tools never add user or group accounts, and that is why the administrator can specify scripts for all such operations. If the scripts are not specified in the&lt;b&gt;&lt;i&gt; smb.conf&lt;/i&gt;&lt;/b&gt; file, Samba will reject an attempt to add a use for which there exists no POSIX (system) account. Samba tools do not interfere with file and directory access controls.&lt;/li&gt;
&lt;li&gt;Because Samba must deal with the semantics that are used by MS Windows networking, it provides a method by which network access can be controlled. The &lt;b&gt;&lt;i&gt;pdbedit&lt;/i&gt;&lt;/b&gt; tool is the primary command-line tool by which these control may be affected.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;The pdbedit tool&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The pdbedit tool can only be used by root. It is used to manage the passdb backend, and domain-wide account policy settings. In general, pdbedit can be used to:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;list user and group accounts&lt;/li&gt;
&lt;li&gt;migrate user, machine and group accounts&lt;/li&gt;
&lt;li&gt;manage account policies&lt;/li&gt;
&lt;li&gt;manage domain access policy settings&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Under the terms of the Sarbanes-Oxley Act of 2002, American businesses and organizations are mandated to implement a series of internal controls and procedures to communicate, store and protect financial data. This legislation has far-reaching implications, with respect to the following issues:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;who has access to information systems that store financial data&lt;/li&gt;
&lt;li&gt;how personal and financial information is treated among employees and business partners&lt;/li&gt;
&lt;li&gt;how security vulnerabilities are managed&lt;/li&gt;
&lt;li&gt;security- and patch-level maintenance for all information systems&lt;/li&gt;
&lt;li&gt;how information systems changes are documented and tracked&lt;/li&gt;
&lt;li&gt;how information access controls are implemented and managed&lt;/li&gt;
&lt;li&gt;audit ability of all information systems in respect of change and security&lt;/li&gt;
&lt;li&gt;disciplinary procedures and controls to ensure privacy.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
In short, the Sarbanes-Oxley Act of 2002 is an instrument of law that demands accountability in regards to business-related information systems, so as to ensure the compliance of all information systems that are used to store personal information and, particularly, for financial records processing. Similar accountabilities are being demanded around the world.&lt;br /&gt;
&lt;br /&gt;
The need to be familiar with the Samba tools and facilities that permit information systems operation compliance with government laws and regulations is clear to all. The &lt;b&gt;&lt;i&gt;pdbedit&lt;/i&gt;&lt;/b&gt; utility is currently the only Samba command line-driven tool that provides the capacity to manage account, systems access controls and policies. During the remaining life-cycle of the Samba-3 series, it is possible the new tools may be implemented to aid in this important area.&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;&lt;i&gt;pdbedit&lt;/i&gt;&lt;/b&gt; tool is the lone device that can manage account security and policy settings. It is capable of superset of the old Samba smbpasswd capabilities. One particularly important purpose of the pdbedit, is to allow the migration of account information from one passdb backend to another.&lt;br /&gt;
&lt;br /&gt;
So, let&#39;s get down to brass tacks, or brass code. In part two of this tip, I&#39;ll show you how to create Linux system user and group accounts; create Windows group accounts; map Windows group accounts to Linux group accounts; add Windows user accounts; and establish network access policies and controls.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-4-of-6-pdbedit.html&quot;&gt;Continue to part two&lt;/a&gt;&amp;nbsp;of this tip.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/8012363037589432198/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-4-of-6-pdbedit_27.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/8012363037589432198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/8012363037589432198'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-4-of-6-pdbedit_27.html' title='Managing Samba (Part 4 of 6): The pdbedit utility, part 1'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-4279239986102892781</id><published>2010-10-27T17:34:00.000-06:00</published><updated>2010-10-27T17:34:03.453-06:00</updated><title type='text'>Managing Samba (Part 3 of 6): Configuration for remote management, part two</title><content type='html'>You tasted basic Samba configuration in part one of this tutorial. Now, let&#39;s get into something much meatier: Samba PDC (primary domain controller) configuration.&lt;br /&gt;
&lt;br /&gt;
The following &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file contents demonstrate the use of the key parameters as well as a few additional ones required to round out a Samba primary domain controller. The key point to observe is the settings for the interface scripts. The example uses the &lt;b&gt;&lt;i&gt;passdb backend = tdbsam&lt;/i&gt;&lt;/b&gt;, and this means that this PDC is not -- I repeat, not -- suitable for use with a BDC (backup domain controller).&lt;br /&gt;
&lt;br /&gt;
A PDC that has the configuration file shown in this example is a subset of the configuration that is depicted in the book, Samba-3 by Example, second edition. The extracted example does not make use of WINS (the Windows Internetworking Name Server) for NetBIOS to IP address name resolution and eliminates a few more refinements. In this article, my objective is to demonstrate a more basic configuration. The example file is fully functional, but it lacks some of the bells and whistles that can be used to create a more stable environment. The latter Samba environment can be obtained by carefully following the examples in the book.&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;&lt;i&gt;[homes] &lt;/i&gt;&lt;/b&gt;share is properly called a meta-service and is used to dynamically create a user home folder share from the Unix system account information.&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;&lt;i&gt;[printers] &lt;/i&gt;&lt;/b&gt;share is another example of a meta-service. In this case, it defines the generic Unix directory into which a print job will be spooled until it is ready to be sent to a Unix system printer by way of a standard operating system print command. Where CUPS (the Common Unix Print System) is used, Samba will pass the print job directly via a built-in CUPS library interface.&lt;br /&gt;
&lt;br /&gt;
The permissions on the &lt;b&gt;&lt;i&gt;/var/spool/samba &lt;/i&gt;&lt;/b&gt;directory should be set by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;chmod 1777 /var/spool/samba&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;chown root /var/spool/samba&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;chgrp users /var/spool/samba&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
The &lt;b&gt;&lt;i&gt;[netlogon] &lt;/i&gt;&lt;/b&gt;share is necessary for domain controller operation. The &lt;b&gt;&lt;i&gt;logon.bat&lt;/i&gt;&lt;/b&gt; script specified in the smb.conf file must be stored in DOS file format in a directory called scripts inside the &lt;b&gt;&lt;i&gt;/var/lib/samba/netlogon&lt;/i&gt;&lt;/b&gt; directory.&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;&lt;i&gt;[profiles]&lt;/i&gt;&lt;/b&gt; directory will permit the storage of Windows roaming profiles. The permissions on this directory are important and should be set so that the default group can write to the directory. An example of suitable configuration is:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;chown root /var/lib/samba/profiles&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;chgrp users /var/lib/samba/profiles&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;chmod 2775 /var/lib/samba/profiles&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
As domain users log onto and then out of the Windows workstations that are domain members, the users profiles will be written automatically to the directory &lt;b&gt;&lt;i&gt;/var/lib/samba/profiles/&#39;username&#39;&lt;/i&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[global]&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;workgroup = ROSESARERED&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;netbios name = VIOLETSBLUE&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;passdb backend = tdbsam&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;username map = /etc/samba/smbusers&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;enable privileges = Yes&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;log level = 0&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;log file = /var/log/samba/%m.log&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;max log size = 50&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;add user script = /usr/sbin/useradd -m &#39;%u&#39;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;delete user script = /usr/sbin/userdel -r &#39;%u&#39;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;add group script = /usr/sbin/groupadd &#39;%g&#39;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;delete group script = /usr/sbin/groupdel &#39;%g&#39;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;add user to group script = /usr/sbin/usermod -G &#39;%g&#39; &#39;%u&#39;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;set primary group script = /usr/sbin/usermod -g &#39;%g&#39; &#39;%u&#39;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;add machine script = /usr/sbin/useradd -s /bin/false -d /dev/null &#39;%u&#39;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;logon script = scripts\logon.bat&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;logon path = \\%L\profiles\%U&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;logon drive = h:&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;logon home = \\%L\%U&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;domain logons = Yes&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[homes]&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;comment = Home Directories&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;valid users = %S&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;read only = No&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;browseable = No&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[printers]&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;comment = SMB Print Spool&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;path = /var/spool/samba&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;guest ok = Yes&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;printable = Yes&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;use clientdriver = Yes&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;default devmode = Yes&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;browseable = No&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[netlogon]&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;comment = Network Logon Service&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;path = /var/lib/samba/netlogon&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;guest ok = Yes&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;locking = No&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[profiles]&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;comment = Profile Share&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;path = /var/lib/samba/profiles&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;read only = No&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;profile acls = Yes&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Before starting Samba&#39;s smbd and nmbd daemons, the contents of the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file can be validated by executing &lt;b&gt;&lt;i&gt;testparm&lt;/i&gt;&lt;/b&gt;. This is a very useful tool to verify that there are no critical errors or typos.&lt;br /&gt;
&lt;br /&gt;
It may be useful to rename &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file to &lt;b&gt;&lt;i&gt;smb.conf.master&lt;/i&gt;&lt;/b&gt;, and then let the &lt;b&gt;&lt;i&gt;testparm&lt;/i&gt;&lt;/b&gt; utility generate the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;testparm -s smb.conf.master &amp;gt; smb.conf&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The resulting &lt;b&gt;&lt;i&gt;smb.conf &lt;/i&gt;&lt;/b&gt;file will be fully optimized. Additionally, if there are any significant errors, these will be reported as the file is created.&lt;br /&gt;
&lt;br /&gt;
If all went well, go ahead and start Samba. Check the documentation for your operating system platform for information regarding how to start the smbd and nmbd daemons. Alternatively, refer to chapter 1 of the book, &lt;b&gt;The Official Samba-3 HOWTO&lt;/b&gt; and &lt;b&gt;Reference Guide, 2nd Edition&lt;/b&gt;, for further Samba start-up information.&lt;br /&gt;
&lt;br /&gt;
Operation of Samba can be validated by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;#&amp;gt; smbclient -L localhost -U%&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Domain=[ROSESARERED] OS=[Unix] Server=[Samba 3.0.21]&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Sharename Type Comment&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;--------- ---- -------&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;netlogon Disk&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;profile Disk&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;IPC$ IPC IPC Service (Main Server)&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ADMIN$ IPC IPC Service (Main Server)&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;hp940 Printer HP DeskJet 940c&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Cups-PDF Printer Cups-PDF&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Domain=[ROSESARERED] OS=[Unix] Server=[Samba 3.0.21]&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Server Comment&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;--------- -------&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;VIOLETBLUE Main Server&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Workgroup Master&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;--------- -------&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ROSESARERED VIOLETBLUE&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If you&#39;ve made it this far, then the Samba server is operative and it should now be possible to administer it remotely. Congratulations!&lt;br /&gt;
&lt;br /&gt;
If you want to keep reading, go to the &lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-4-of-6-pdbedit_27.html&quot;&gt;next article by clicking here.&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/4279239986102892781/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-3-of-6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/4279239986102892781'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/4279239986102892781'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-3-of-6.html' title='Managing Samba (Part 3 of 6): Configuration for remote management, part two'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-4036787907651432797</id><published>2010-10-27T17:31:00.000-06:00</published><updated>2010-10-27T17:31:52.959-06:00</updated><title type='text'>Managing Samba (Part 3 of 6): Configuration for remote management, part 1</title><content type='html'>Samba is the bridge between Linux and Microsoft worlds. Samba-3 can help administrators create transparent interoperability of Microsoft Windows client with a Unix or Linux server environment. Even so, seamless interoperability is not easy to achieve, but mastering some Samba configuration tasks helps. So, let&#39;s get started with this tutorial on &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Use the configuration parameters in the Samba &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; configuration control file to permit the transparent management of Samba using tools that are native to the Microsoft Windows environment.&lt;br /&gt;
&lt;br /&gt;
By the way, this is the third installment in a series on Managing Samba. The first article in this series explains how Samba handles Windows security identifiers. The second tip describes user rights and privileges in the Microsoft Windows networking environment.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Anatomy of a Samba configuration&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To appreciate the complexity involved in creating transparent interoperability of a Microsoft Windows client with a Unix or Linux environment, open up a system shell on your Samba host server and execute this command:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;testparm -sv | more&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You will soon discover that there are over 300 parameters that are capable of being set in the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; configuration file. While it may be tempting to discuss every one of them, this is not necessary. Even a complex Samba configuration can usually be accomplished using fewer than 30 specific parameters in the [global] section of the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file.&lt;br /&gt;
&lt;br /&gt;
The parameters fit into a set of functional categories. The functional categories determine how Samba will interact with Windows networking protocols, how Samba will interact with the underlying Unix file system and how Samba will interface with the host operating system.&lt;br /&gt;
&lt;br /&gt;
In this next section, I&#39;ll list some terms that summarize commonlyused configuration parameters.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Base parameters&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;netbios name - sets the machine name (i.e. the computer name). If not set, the name of the host server will be used&lt;/li&gt;
&lt;li&gt;netbios aliases - can be used to present the Samba server under multiple computer names&lt;/li&gt;
&lt;li&gt;workgroup - sets the workgroup name (the same as an NT4 domain name)&lt;/li&gt;
&lt;li&gt;realm - is applicable only when Samba is an Active Directory domain member&lt;/li&gt;
&lt;li&gt;interfaces - instructs Samba which network interfaces to use -- when used with &lt;b&gt;&lt;i&gt;bind interfaces only = Yes&lt;/i&gt;&lt;/b&gt; instructs Samba to provide file services (TCP ports 139 or 445) only on the specified interfaces. NetBIOS name resolution services (UDP ports 137 and 138) will work on all interfaces.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lightweight Directory Access protocol (LDAP) controls&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
LDAP controls are only necessary when Samba is run as a primary domain controller/backup domain controller (PDC/BDC) combination. Basic mandatory controls when using an LDAP directory to store Samba account credentials include:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;ldap admin dn - defines the administrative DN needed to write to LDAP&lt;/li&gt;
&lt;li&gt;ldap suffix - defines the base directory information tree&lt;/li&gt;
&lt;li&gt;ldap [user,group,machine,idamp] suffix - sets the container in which various accounts records are stored&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Logging parameters&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The default parameter values are usually adequate and normally used for debugging. Commonly used parameters include:&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;log level&lt;/i&gt;&lt;/b&gt; - sets the diagnostic intensity level.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Typical values are:&amp;nbsp;&lt;/li&gt;
&lt;li&gt;0 - Record only critical errors&amp;nbsp;&lt;/li&gt;
&lt;li&gt;1 - default&amp;nbsp;&lt;/li&gt;
&lt;li&gt;3 - For debugging simple file system access problems&amp;nbsp;&lt;/li&gt;
&lt;li&gt;5 - For complex system diagnostics&amp;nbsp;&lt;/li&gt;
&lt;li&gt;10 - Permit detailed diagnosis of authentication errors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;log file&lt;/i&gt;&lt;/b&gt; - specifies the name of the log files.&lt;br /&gt;
&lt;br /&gt;
Example: /var/log/samba/%m.log - creates a separate log per client&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;max log size&lt;/i&gt;&lt;/b&gt; - sets size limit at which Samba should rotate the log file. The file is renamed to oldfile.log and a new file is created.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;System interface scripts&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The system interface scripts are called when an external application requires management of host operating system environment information. An external application can be the NT4 Domain User Manager or the Samba net utility. When a Windows client is joined to the domain, the add machine script is called to create the Unix system account that is needed so that the appropriate SambaSAMAccount entry can be created to store the machine trust account information.&lt;br /&gt;
&lt;br /&gt;
Examples of necessary actions include user/group account manipulation, add/edit/delete shares, add/edit/delete printers, call system initialization scripts, etc. The common parameters needed are as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Account management: add group script, add machine script, add user script, add user to group script, delete group script, delete user from group script, delete user script, set primary group script, rename user script&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Note: Where LDAP is used the scripts specified should be able to manage the directory contents. Where LDAP is not used the normal U system account management tools can be specified. For example: add user scriptl= /usr/bin/useradd -m &#39;%u&#39;.&lt;/li&gt;
&lt;li&gt;Resource management: add share command, change share command, delete share command, add printer command, delete printer command, abort shutdown script, shutdown script&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Samba operating mode parameters&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s move on to Samba operating mode parameters:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;i&gt;domain logons&lt;/i&gt;&lt;/b&gt; - when set to Yes, Samba will enable the network logon service. This creates the domain control capabilities needed for a PDC/BDC.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;enable privileges&lt;/i&gt;&lt;/b&gt; - when set to Yes, enables assignment of rights and privileges.&amp;nbsp;&lt;b&gt;Note&lt;/b&gt;: only Samba-3.0.11 and later.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;logon drive&lt;/i&gt;&lt;/b&gt; - lets the drive that Windows NT4/200x/XP clients will associate with the execution of network logon scripts. This is the drive to which the home directory will be mounted if net use /home is executed on a Windows client, either in a command shell or from the logon script.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;logon home&lt;/i&gt;&lt;/b&gt; - used only by Windows 9x/Me clients.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;logon script&lt;/i&gt;&lt;/b&gt; - the logon script that is executed when a user logs onto a domain member client.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;passdb backend&lt;/i&gt;&lt;/b&gt; - specifies which backend system Samba will use to store&amp;nbsp;&lt;b style=&quot;font-style: italic;&quot;&gt;SambaSAMAccount &lt;/b&gt;information. The default is smbpasswd, the two common alternatives are tdbsam and ldapsam. Both the ldapsam and the tdbsam types are capable of storing the advanced SambaSAMAccount information. The smbpasswd method is not capable of storing the advanced account information.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;security&lt;/i&gt;&lt;/b&gt; - this parameter sets the Samba server mode. Acceptable settings are:&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;user&lt;/i&gt;&lt;/b&gt; - means Samba is either a standalone server or a domain controller.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;domain&lt;/i&gt;&lt;/b&gt; - means Samba is an NT4-style domain member.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;ads&lt;/i&gt;&lt;/b&gt; - means Samba is an Active Directory member (uses Kerberos authentication and security, but only as a member -- not as an ADS domain controller.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;server&lt;/i&gt;&lt;/b&gt; - means that Samba is not a domain member, but is using an external authentication server. Uses pass-through authentication that has been largely obsolete.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;domain master&lt;/i&gt;&lt;/b&gt; - Leave this set at the default value on all systems except a BDC. On a BDC, this parameter must be set to No.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
There are many additional parameters that are useful for specific purposes. Refer to the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; online main page for detailed information regarding each parameter.&lt;br /&gt;
&lt;br /&gt;
For the most part, the setting of unnecessary parameters in the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; files is unnecessary and potentially problematic. It is very good advice to keep the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file as simple as possible.&lt;br /&gt;
&lt;br /&gt;
Now that your appetite is whetted for Samba configuration, I&#39;ve got a new treat for you. Move on to part two for an example of a Samba PDC configuration. I&#39;m sure you&#39;ll find it very satisfying.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-3-of-6.html&quot;&gt;Click here&lt;/a&gt; to read part two of this tip.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/4036787907651432797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-3-of-6_27.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/4036787907651432797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/4036787907651432797'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-3-of-6_27.html' title='Managing Samba (Part 3 of 6): Configuration for remote management, part 1'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-6652693378987011484</id><published>2010-10-27T17:30:00.000-06:00</published><updated>2010-10-27T17:30:19.103-06:00</updated><title type='text'>Managing Samba (Part 2 of 6): User rights and privileges</title><content type='html'>When faced with making Linux and Windows work together securely, system administrators can run into trouble if they don&#39;t understand or can&#39;t correctly use the administrative security controls that are present in the Microsoft Windows operating system (OS) and the Samba-3 equivalents of those controls.&lt;br /&gt;
&lt;br /&gt;
So, let&#39;s take a look at the tools administrators should be familiar with and the rights and privileges that can be managed.&lt;br /&gt;
&lt;br /&gt;
This is part two of &amp;nbsp;a six-part series, titled Managing Samba. In part one, I covered Windows network identity basics. Stay tuned, as the next article in this series will review the process of establishing a Samba configuration that is able to be securely managed using traditional Windows administrative tools.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Why user rights and privileges matter&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Many people get confused by the fact that, by design, Windows NT/2000/XP provides the capacity to restrict access to almost every part of the operating system, yet the facilities that permit files and directories to be secured through use of restrictive access controls are frequently ill-used, if they&#39;re used at all.&lt;br /&gt;
&lt;br /&gt;
Microsoft Windows XP Home Edition is commonly configured so that the default user has full administrative privilege and thus bypasses most native operating system security provisions. It is, therefore, no wonder that virus and worm infections can march forward with the utmost pace and force.&lt;br /&gt;
&lt;br /&gt;
Many users expect to have the ability to create accounts and to install software without constraint. My objective is not to discuss the defense mechanisms against virus and worm activity, but to focus on administrative rights and user capabilities.&lt;br /&gt;
&lt;br /&gt;
Windows XP Home Edition does not provide the ability to manage file system access controls. In every respect therefore, the dominant operating system in the consumer market place, Windows XP Home Edition, provides little to no security control capability.&lt;br /&gt;
&lt;br /&gt;
Windows XP Professional provides the capability to manage access control lists (ACLs) on file system resources, but few people learn how to manage them effectively. Despite this, ACLs are a valuable asset in a networked environment and are a common part of Windows security domains. Windows XP Professional also permits the assignment of administrative tasks to users and groups. These facilities are of significant importance in the creation and maintenance of a secure networking environment.&lt;br /&gt;
&lt;br /&gt;
A key reason for the exercise of constraint in corporate networks is the protection of data and, in particular, the protection of confidential data. In the U.S., the Sarbanes-Oxley Act of 2002 is used to enforce restrictive data access in many industries.&lt;br /&gt;
&lt;br /&gt;
Samba-3 is transparent in respect of file system security controls. So long as the underlying file system of the server on which Samba is being hosted has ACL support and, providing that Samba-3 has been compiled to support the handling of ACLs, Windows administrators and users will have the ability to manage ACLs on exported file systems on the Samba-3 server.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Windows domain membership and security&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Machine (computer) accounts are used in the Windows NT OS family to store security credentials for domain member servers and workstations. A computer account is created when a Windows client joins a Windows NT4 domain, or when it is made a member of a Microsoft Windows 200x Active Directory domain.&lt;br /&gt;
&lt;br /&gt;
As part of the startup process of a domain member machine, it goes through a validation procedure that includes an exchange of credentials with a domain controller. If the domain member fails to authenticate, using the credentials known for it by domain controllers, the machine will be refused all access by domain servers.&lt;br /&gt;
&lt;br /&gt;
Within the context of a domain logon, the computer account is essential to the way that Microsoft Windows secures authentication. The computer account is used only to authenticate domain member machines during the startup, a security measure designed to block man-in-the-middle attempts to violate network integrity.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Windows Domain Administration Controls&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
By default, the ability to add machines to the domain is limited to the Windows domain administrator account. The right for other users or groups to add machines to the domain can be granted by the administrator using the appropriate tool.&lt;br /&gt;
&lt;br /&gt;
The Windows NT4 server management tool can be used to manage domain member machines (servers and workstations). The right to add workstations to the Windows NT4 domain can be granted using the Windows NT4 domain user manager. This particular privilege that must be assigned to a user or group so that they can add machines to the domain is called &lt;b&gt;&lt;i&gt;SeMachineAccountPrivilege&lt;/i&gt;&lt;/b&gt;. The title in the NT4 domain user manager rights management panel is called &lt;b&gt;&lt;i&gt;Add workstations to domain&lt;/i&gt;&lt;/b&gt;. The list of available privileges that can be assigned in Windows NT4 is shown here:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1WOMAcBUYAvs58XlN4TVZnJmyKzyW0VCzyOigy6_7_ttkXWAZju2Ven4DhX3TFcx6kvrhKRKb0NQ3GHW9tjgmEKnQElDlz4bLO-xAZgwwCuF1nMcFxlBsywBJxC5EtlvoqqTpZl6XQwez/s1600/managing_samba_1.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;316&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1WOMAcBUYAvs58XlN4TVZnJmyKzyW0VCzyOigy6_7_ttkXWAZju2Ven4DhX3TFcx6kvrhKRKb0NQ3GHW9tjgmEKnQElDlz4bLO-xAZgwwCuF1nMcFxlBsywBJxC5EtlvoqqTpZl6XQwez/s400/managing_samba_1.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Additional Windows privileges were added in Windows 2000 and are also available in Windows 2003 and Windows XP Professional. These may be found in Figure 2.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUaQ9IbKx2Tb_kunX9ldFJpkdF2wNpHU4wntesr7j7ZUhkRAeKc-NkFri6BT-aR3aBkVo0hbj2x_Py-1tKxE1058mEDX6D9HNulq1raYDeDrQ747JGqgtS3PL_W2wSbTaDniAAs4EiEtp2/s1600/managing_samba_2.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;125&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUaQ9IbKx2Tb_kunX9ldFJpkdF2wNpHU4wntesr7j7ZUhkRAeKc-NkFri6BT-aR3aBkVo0hbj2x_Py-1tKxE1058mEDX6D9HNulq1raYDeDrQ747JGqgtS3PL_W2wSbTaDniAAs4EiEtp2/s400/managing_samba_2.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
The Windows 200X privileges are a super-set of those available with Windows NT4. Some of the privileges present in the Windows NT4/200X environments are of unique relevance to those operating systems and have no direct equivalent in a UNIX- or Linux-based Samba environment.&lt;br /&gt;
&lt;br /&gt;
The privileges that make sense within a Linux environment have been implemented in Samba-3.0.x since the 3.0.11 release. These are summarized below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhAcjSFpkvk8Q91bq-0HWIGNI5o6sAb9nxLPHsYWfXX_Ahumg_aTwJ51WbHsGeV0nrKwxvLXiPBzcftAlzkr0zMXQwHKVAuz-TA18nbjUXHfsUZj8mDyty5QwCeTf9RntvL0H4Cf3QH0nG/s1600/managing_samba_3.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;118&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhAcjSFpkvk8Q91bq-0HWIGNI5o6sAb9nxLPHsYWfXX_Ahumg_aTwJ51WbHsGeV0nrKwxvLXiPBzcftAlzkr0zMXQwHKVAuz-TA18nbjUXHfsUZj8mDyty5QwCeTf9RntvL0H4Cf3QH0nG/s400/managing_samba_3.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
In comparing the privileges that are present in Samba with those supported by Microsoft Windows NT4/2000/2003, those found in Samba are also supported in Windows server products.&lt;br /&gt;
&lt;br /&gt;
Windows administrative privileges can be assigned to Windows users and Windows groups, thereby permitting relatively fine-grained assignment of administrator privileges on an as-needed basis. For example, where it is desirable that a Windows user called &lt;b&gt;&lt;i&gt;joebartemy&lt;/i&gt;&lt;/b&gt; should be able to add Windows clients to the domain, his account can be assigned the &lt;b&gt;&lt;i&gt;SeMachineAccountPrivilege&lt;/i&gt;&lt;/b&gt; thus preventing this user from gaining any other administrative capabilities. Likewise, members of the Windows group &lt;b&gt;&lt;i&gt;Marketing Staff &lt;/i&gt;&lt;/b&gt;can be given the ability to manage printers and print jobs by granting this group the &lt;b&gt;&lt;i&gt;SePrintOperatorPrivilege&lt;/i&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Allocating administrative privileges&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Samba versions prior to 3.0.11 required the use of a UNIX account that has UID=0 (the root account) for a number of core administrative operations. Operations that require this level of privilege within the Unix operating system environment include management of user and group accounts, change of file ownership, print job management and so on. Older versions of Samba provided work-around methods to permit some of these essential tasks to be completed. Those that could not be side-stepped simply had to be done by the root account, or its equivalent.&lt;br /&gt;
&lt;br /&gt;
Samba-3.0.11 and later allow the creation and administration of a Samba server without needing to resort to the use of the root account. Users who are members of the Domain Admins group automatically have the necessary privileges to manage all aspects of Samba. Those who need to be assigned specific roles can be given the minimum level of access necessary to perform the tasks they are responsible for. Someone who has been given the&lt;b&gt;&lt;i&gt; SeMachineAccountPrivilege&lt;/i&gt;&lt;/b&gt; can add machines to the domain and those who have been given the &lt;b&gt;&lt;i&gt;SePrintOperatorPrivilege&lt;/i&gt;&lt;/b&gt; can now manage printers, print jobs and more.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Management of Windows administrative privileges&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Samba-3 provides a command-line tool for the management of user rights and privileges. The use of the net utility, as well as the administration of user rights and privileges are documented in the Samba3-HOWTO book, and correct has also been documented in the Samba3-ByExample book.&lt;br /&gt;
&lt;br /&gt;
An example of use of the net command to assign the ability to add machines -- Samba servers, Windows servers and clients -- to the Samba domain for the domain &lt;b&gt;&lt;i&gt;MIDEARTH&lt;/i&gt;&lt;/b&gt; and the user &lt;b&gt;&lt;i&gt;jerry&lt;/i&gt;&lt;/b&gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;net rpc rights grant &quot;MIDEARTH\jerry&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SeMachineAccountPrivilege -S PDC -&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Ujtadmin%password&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
This operation can also be performed by using the Windows NT4 Domain User Manager. This handy utility may be obtained from the Microsoft support Web site. A more recent version of this tool is also available.&lt;br /&gt;
&lt;br /&gt;
An example of use is demonstrated in Figure 4.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPeJ6H1Cl0DIO_AhstWmwf1f62VzYPlvNellU33HuJ0_1Q9qwyvhnEmKQ14663N7cwWdGgUci6WdzjdN8wOMcOeogdTvxpBcO_VzknYPY9m8TwuvjL_2qdwjo25zB5UwZ_Tp06g98nXrGL/s1600/managing_samba_4.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;326&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPeJ6H1Cl0DIO_AhstWmwf1f62VzYPlvNellU33HuJ0_1Q9qwyvhnEmKQ14663N7cwWdGgUci6WdzjdN8wOMcOeogdTvxpBcO_VzknYPY9m8TwuvjL_2qdwjo25zB5UwZ_Tp06g98nXrGL/s400/managing_samba_4.gif&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The steps that lead up to this Windows panel are:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Log onto Windows XP Professional as a user who has administrative rights.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Launch the UsrMgr.exe.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Click on the Policy tab.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Click on the User Rights entry.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Another tool that can be used to manage user rights is a commercial package called Hyena. The latest at the time of preparation of this article was version 6.5.&lt;br /&gt;
&lt;br /&gt;
The &lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-3-of-6_27.html&quot;&gt;next article&lt;/a&gt; in this series will document the configuration of a Samba domain controller so that user rights and privileges can be managed using the tools we have reviewed here.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/6652693378987011484/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-2-of-6-user-rights.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6652693378987011484'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6652693378987011484'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-2-of-6-user-rights.html' title='Managing Samba (Part 2 of 6): User rights and privileges'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1WOMAcBUYAvs58XlN4TVZnJmyKzyW0VCzyOigy6_7_ttkXWAZju2Ven4DhX3TFcx6kvrhKRKb0NQ3GHW9tjgmEKnQElDlz4bLO-xAZgwwCuF1nMcFxlBsywBJxC5EtlvoqqTpZl6XQwez/s72-c/managing_samba_1.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-7651216550555080112</id><published>2010-10-27T17:27:00.000-06:00</published><updated>2010-10-27T17:27:53.106-06:00</updated><title type='text'>Managing Samba (Part 1 of 6): Choose your weapon</title><content type='html'>Samba has become an integral part of a large portion of the networking marketplace. Despite its prevalence, not all IT shops currently utilize the facilities provided to fully secure the network or to drive operating costs to a minimum.&lt;br /&gt;
&lt;br /&gt;
Samba-3 has grown in capability, as well as in complexity. Linux administrators are keen to learn how better to manage Samba and how to meet the growing demand of network security and audit-ability. This series of articles will help administrators master Samba-3 management. In this first article in a six-part, two-month series, you&#39;ll find a description of the series and a tutorial on Windows network identity basics.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Introduction&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I recently asked a few Windows networking administrators what they believe is needed to help drive down the cost of using Samba. They all said better management tools would be a great help.&lt;br /&gt;
&lt;br /&gt;
After further discussion with these administrators, it became clear that while they were comfortable with Samba, they were unclear where Samba stores user, machine and group information, and how these relate to the network environment. Had the relationships been better understood, the functionality of available administration tools might be better understood and the request for better tools might not be so strong.&lt;br /&gt;
&lt;br /&gt;
This series of articles will provide a better understanding of the relationship between Windows networking accounts and their equivalent on the Unix or Linux server that is running Samba.&lt;br /&gt;
&lt;br /&gt;
I&#39;ve described the topics in the series below. You can also click here to go directly to page two for the tip on Windows network identity.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Series overview&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This series will cover the following subjects:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-1-of-6-windows.html&quot;&gt;Windows networking identity basics&lt;/a&gt;: The first article explores the ways in which Microsoft Windows users gain access to the operating system and how this affects access to network resources. It will also explore what a Samba server must do to handle incoming network connection requests from Windows workstations. Specifically, the article will show how Samba deals with identity issues, where it stores the data it uses and how each component of Windows networking identities can be managed. The article concludes with basic rules that make it possible to operate the Samba environment with a minimum of administrative overhead.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-2-of-6-user-rights.html&quot;&gt;A comparison of user rights and privilege management in Windows and Samba&lt;/a&gt;: The second article will explain how Windows workstation users gain, or can be denied, various local and network-wide rights and privileges. It then will examine how this can be implemented in a Samba environment.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-3-of-6_27.html&quot;&gt;The creation of a network-wide remote management infrastructure&lt;/a&gt;: The next article focuses on how Samba can be configured to create an environment that is conducive to centralized network management. It will provide information on where to obtain detailed technical guidance, so that the necessary infrastructure can be implemented without undue difficulty.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-4-of-6-pdbedit_27.html&quot;&gt;Use of the pdbedit utility to manage user accounts and to configure network security settings:&lt;/a&gt; The pdbedit utility has become a strategically important tool for managing Windows network user accounts. It is also important to sites that need to comply with the requirements of the Sarbanes-Oxley Act. The article will discuss how this tool can be used to set password expiration limits and reconfigure the location of a user&#39;s home folder or the location of the user&#39;s roaming profile, and so on. Additionally, the article will explain how to disable roaming profiles for all or for some users and will provide guidelines for Windows workstation configuration to bring sanity to network management.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6_26.html&quot;&gt;The use of the net utility to perform remote network management:&lt;/a&gt; The article will show how the net utility can be used to perform many essential network management and control operations. This versatile tool can be used to manage users, groups and group membership for Windows networking users. It can also be used to migrate servers and server resources across various Windows and Samba servers.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-6-of-6-remote-gui.html&quot;&gt;The use of various remote management tools:&lt;/a&gt; This closing article will examine the leading solutions to the remote network management challenge. An overview will be provided covering the NT4 SRVTOOLS, the LDAP administrator, the IMC console, the LDAP Administration Manager (LAM), and a commercial tool (yet to be chosen).&lt;/li&gt;
&lt;/ul&gt;Continue to the next article for the tip, &lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-1-of-6-windows.html&quot;&gt;Managing Samba: Windows networking identity basics&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/7651216550555080112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-1-of-6-choose-your.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/7651216550555080112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/7651216550555080112'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-1-of-6-choose-your.html' title='Managing Samba (Part 1 of 6): Choose your weapon'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-1598411293115645262</id><published>2010-10-27T15:35:00.002-06:00</published><updated>2010-10-28T10:39:27.792-06:00</updated><title type='text'>A collection of the top Linux command tips</title><content type='html'>As a sysadmin, you’ll need to use the command line instead of the GUI from time to time. Do you know how to monitor what’s running on your Linux server through the command line? Can you confidently unlock the copying prowess of the dd command? Brush up on your command-line skills with this collection of expert advice -- a list of the 8 top Linux command tips.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/using-grep-and-sed-to-find-and-replace.html&quot;&gt;Using grep and sed to find and replace&lt;/a&gt;&lt;br /&gt;
Using the Linux commands grep and sed can help search for a string of text within a file and replace strings.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/linuxunix-commands-how-to-get-copy.html&quot;&gt;Linux/Unix commands: How to get copy, conversion power with dd&lt;/a&gt;&lt;br /&gt;
The Linux command dd handles convert-and-copy tasks, and aids in cloning the hard drive, among other tasks.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/how-to-manage-software-on-ubuntu-server.html&quot;&gt;How to manage software on Ubuntu Server with &quot;aptitude&quot; and &quot;apt-get&quot;&lt;/a&gt;&lt;br /&gt;
In this tip, learn how to use aptitude and apt-get to perform Linux package management.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/keep-eye-on-linux-processes-with-ps.html&quot;&gt;Keep an eye on Linux processes with ps&lt;/a&gt;&lt;br /&gt;
By using the command-line tool ps, you can monitor what’s running on your Linux server.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6_26.html&quot;&gt;Samba management: Configuration with the net utility, part 1&lt;/a&gt;&lt;br /&gt;
The first installment of a tip series that explains using the net utility to configure the primary domain controller and manage a server in Samba.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/managing-samba-part-5-of-6.html&quot;&gt;Samba management: Configuration with the net utility, part 2&lt;/a&gt;&lt;br /&gt;
Part 2 of a tip that explains using the net utility to configure the primary domain controller and manage a server in Samba.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/understanding-linux-system-performance.html&quot;&gt;Understanding Linux system performance management using top&lt;/a&gt;&lt;br /&gt;
Using the Linux command top can provide sysadmins with system performance data. Learn how to analyze these top results, including data such as load average values.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://amadys.blogspot.com/2010/10/analyzing-linux-write-performance.html&quot;&gt;Analyzing Linux write performance problems with iotop&lt;/a&gt;&lt;br /&gt;
There could be write performance problems on your Linux system, and the iotop Linux command may be more detailed than top in getting to the root of the performance issues.&lt;br /&gt;
&lt;br /&gt;
Be sure to also check out this &lt;u style=&quot;font-style: italic;&quot;&gt;comprehensive guide to 77 useful Linux commands and utilities,&lt;/u&gt;&amp;nbsp;coming&amp;nbsp;soon !!</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/1598411293115645262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/collection-of-top-linux-command-tips.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/1598411293115645262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/1598411293115645262'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/collection-of-top-linux-command-tips.html' title='A collection of the top Linux command tips'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-7938470872280307545</id><published>2010-10-27T15:03:00.001-06:00</published><updated>2010-10-27T15:32:01.037-06:00</updated><title type='text'>Analyzing Linux write performance problems with iotop</title><content type='html'>A common performance problem for servers is writing data. When the server writes too much data, the storage sub-channel isn&#39;t able to catch up. But, it can be difficult to discover the performance problems, so here we&#39;ll walk through how to analyze performance issues on Linux servers.&lt;br /&gt;
&lt;br /&gt;
The problem with write performance-related issues, is that often they hide behind other parameters. In all cases however, the top command is a good place to start. The wa parameter in the CPU line indicates the amount of time that your system has been waiting for the I/O-channel. Typically, this indicates a slow storage channel.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh6OblOK7YtYmblE0qVguCN-zTawY2AHB-kaxjfGGFzboewBhTCT8XAmwhEVB2UX11PlxWL5QuRu-Ik38UhCSSsVI8DWr5MztR5wUy0P2HNUtjC0uOEtu_1ctEyF2ciYdUiErywtP41Gdx/s1600/top1-sm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;261&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh6OblOK7YtYmblE0qVguCN-zTawY2AHB-kaxjfGGFzboewBhTCT8XAmwhEVB2UX11PlxWL5QuRu-Ik38UhCSSsVI8DWr5MztR5wUy0P2HNUtjC0uOEtu_1ctEyF2ciYdUiErywtP41Gdx/s400/top1-sm.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
A high value at the wa parameter indicates that the storage channel is suffering&lt;br /&gt;
&lt;br /&gt;
Just looking at top however is not good enough. Let&#39;s have a look at a small test. In this test, we have written the current memory state to disk, using &lt;b&gt;&lt;i&gt;dd if=/dev/kcore of=/kcore.img bs=4096&lt;/i&gt;&lt;/b&gt;. On a 4 GB machine, that is a lot of work for the machine to do. While performing the job, everything else really slows down, which means there is a performance problem.&lt;br /&gt;
&lt;br /&gt;
But, the problem with top is that it&#39;s not really easy to see the write performance problem. It all depends on the amount of CPU cores you have. On a 16-core server, the write problem may claim all CPU cycles on one CPU. You would however not see that from the generic top overview as this gives you the average for all CPU&#39;s together. So with a CPU core that is completely claimed by writes, you wouldn&#39;t see much more than 6% at the wa parameter in top. To get more detail, the first thing to do, is to press the 1 key in the top interface, which gives you a line for each CPU core. On the test system used for writing this article, there are two cores only, so the results are not spectacular. But, on a multi-core system the differences displayed may be important.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTeFM8E_DaEI8fKerCmKJhqpW-ew0bg_5fXnZEb4BSE5A07SwNNRqqfcQ-zLYhO_ZNelHw0BuX06RkVpgzratuviHr2Bs6a_T6EA85h4mSE75weoK4YyWW_ijfewS1Izya_ovYxGFbBp_5/s1600/top2-sm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTeFM8E_DaEI8fKerCmKJhqpW-ew0bg_5fXnZEb4BSE5A07SwNNRqqfcQ-zLYhO_ZNelHw0BuX06RkVpgzratuviHr2Bs6a_T6EA85h4mSE75weoK4YyWW_ijfewS1Izya_ovYxGFbBp_5/s400/top2-sm.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
From top, press 1 to see performance details for each CPU core.&lt;br /&gt;
&lt;br /&gt;
So, if only one core out of 16 cores is completely busy waiting for the slow storage channel, then the 15 remaining cores can do the work, right? Too often, the answer is &quot;no.&quot; If you just have one storage channel, then all CPU&#39;s need to go over that one single channel. If one CPU is completely busy waiting for a storage channel, then the other cores won&#39;t be able to get prompt reactions from the storage channel either. So it may look all right from the top window, but performance could be terribly off.&lt;br /&gt;
&lt;br /&gt;
Fortunately, there is &lt;b&gt;&lt;i&gt;iotop&lt;/i&gt;&lt;/b&gt; and it gives information about the most active processes with regard to I/O. Most Linux distributions don&#39;t install it by default, so make sure you install it manually, using your distributions meta package handler (for instance: yum install iotop if you&#39;re using RHEL). The good thing about &lt;b&gt;&lt;i&gt;iotop&lt;/i&gt;&lt;/b&gt;, is that it shows you which is the most active process with regard to I/O at the moment and how much I/O it is generating. If you compare the I/O load caused by this process with the capacity of your storage channel, you&#39;ll know immediately if you have a storage problem and if so, where it comes from. Then you can troubleshoot this issue, and optimize your Linux server write performance.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJGIvPYoT_wnxcTwkmgrhmk0wp2Sw-eIbYOfY5wuM-7lb6-P7j0jcBwQdFjP23qdoH7f6oE8qqiplPnlrrtMiRV1yO7-8E5vgCmLi4_9MgtGJRN_qoBXLw8dCloflCxK6EfsakDbh_wUAO/s1600/top3-sm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJGIvPYoT_wnxcTwkmgrhmk0wp2Sw-eIbYOfY5wuM-7lb6-P7j0jcBwQdFjP23qdoH7f6oE8qqiplPnlrrtMiRV1yO7-8E5vgCmLi4_9MgtGJRN_qoBXLw8dCloflCxK6EfsakDbh_wUAO/s400/top3-sm.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
With iotop you can see exactly what process is claiming your valuable resources.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/7938470872280307545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/analyzing-linux-write-performance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/7938470872280307545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/7938470872280307545'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/analyzing-linux-write-performance.html' title='Analyzing Linux write performance problems with iotop'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh6OblOK7YtYmblE0qVguCN-zTawY2AHB-kaxjfGGFzboewBhTCT8XAmwhEVB2UX11PlxWL5QuRu-Ik38UhCSSsVI8DWr5MztR5wUy0P2HNUtjC0uOEtu_1ctEyF2ciYdUiErywtP41Gdx/s72-c/top1-sm.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-3270677843648355547</id><published>2010-10-27T14:52:00.001-06:00</published><updated>2010-10-27T15:32:01.046-06:00</updated><title type='text'>Understanding Linux system performance management using top</title><content type='html'>If there&#39;s something wrong with the performance of your Linux server, chances are that you&#39;re already using top to find out what&#39;s happening. It seems however that few people really know how to tell what their system is doing from the information that top provides. Here I will explain how to understand the performance data that top provides.&lt;br /&gt;
&lt;br /&gt;
When starting top, make sure that you are in root. To start, open a console on your favorite Linux distribution and enter the top command. The result should look similar to this:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;host:~ # top&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;top - 12:41:34 up 1 day, &amp;nbsp;3:29, &amp;nbsp;6 users, &amp;nbsp;load average: 0.00, 0.00, 0.00&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Tasks: &amp;nbsp;99 total, &amp;nbsp; 1 running, &amp;nbsp;98 sleeping, &amp;nbsp; 0 stopped, &amp;nbsp; 0 zombie&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Cpu(s): &amp;nbsp;0.1%us, &amp;nbsp;0.1%sy, &amp;nbsp;0.0%ni, 99.7%id, &amp;nbsp;0.1%wa, &amp;nbsp;0.0%hi, &amp;nbsp;0.0%si, &amp;nbsp;0.0%st&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Mem: &amp;nbsp; &amp;nbsp;775064k total, &amp;nbsp; 560056k used, &amp;nbsp; 215008k free, &amp;nbsp; 136216k buffers&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Swap: &amp;nbsp; 136544k total, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0k used, &amp;nbsp; 136544k free, &amp;nbsp; 275624k cached&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; PID USER &amp;nbsp; &amp;nbsp; &amp;nbsp;PR &amp;nbsp;NI &amp;nbsp;VIRT &amp;nbsp;RES &amp;nbsp;SHR S %CPU %MEM &amp;nbsp; &amp;nbsp;TIME+ &amp;nbsp;COMMAND&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;8830 root &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; 0 &amp;nbsp;2232 &amp;nbsp;936 &amp;nbsp;692 R &amp;nbsp; &amp;nbsp;2 &amp;nbsp;0.1 &amp;nbsp; 0:00.03 top&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1 root &amp;nbsp; 16 &amp;nbsp; 0 &amp;nbsp; 728 &amp;nbsp;284 &amp;nbsp;244 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:01.25 init&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2 root &amp;nbsp; RT &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.10 migration/0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3 root &amp;nbsp; 34 &amp;nbsp;19 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.34 ksoftirqd/0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 4 root &amp;nbsp; RT &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.04 migration/1&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5 root &amp;nbsp; 34 &amp;nbsp;19 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.00 ksoftirqd/1&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 6 root &amp;nbsp; 10 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.33 events/0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 7 root &amp;nbsp; 10 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.10 events/1&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 8 root &amp;nbsp; 11 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.01 khelper&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 9 root &amp;nbsp; 12 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.00 kthread&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;13 root &amp;nbsp; 10 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.13 kblockd/0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;14 root &amp;nbsp; 10 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.08 kblockd/1&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;15 root &amp;nbsp; 13 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.00 kacpid&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;16 root &amp;nbsp; 13 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.00 kacpi_notify&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; 227 root &amp;nbsp; 20 &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.00 pdflush&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; 228 root &amp;nbsp; 15 &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.93 pdflush&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; 229 root &amp;nbsp; 17 &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.00 kswapd0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
The first part of relevant information that top provides can be found in the first line: the &lt;b&gt;&lt;i&gt;load average&lt;/i&gt;&lt;/b&gt; parameters. These describe how busy your computer is at the moment. The average workload of your server is always given in three digits. Each represents the load average for the last minute, the last five minutes and the last fifteen minutes. You should always start by interpreting these numbers, as they tell you if your system is overloaded or not.&lt;br /&gt;
&lt;br /&gt;
To understand the load average values, you must relate them to the number of CPU&#39;s or CPU cores in your computer. If you&#39;re not sure, just press the 1 button when the top interface is active, this will give you a line for each CPU core that is present in your computer. When a CPU core has been completely busy in the last minute, top will show you 1.00 if it&#39;s a one core system. If you have eight cores installed in your computer, and one has been completely busy, while the others were doing nothing, top will show you 0.125 as the value in the load average. In order to interpret the value in the load average lines, you need to know the normal value for your server. For instance, on a four-core machine, that would be 4.00. Anything above that value is bad, as it indicates that queuing occurs and processes are waiting for their slice of system time. Anything below this value is good. If your system is getting beyond the ideal value for that system, the next step is to determine what exactly is happening. Listing 2 gives an example of a one-core system that is too busy:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;top - 12:49:38 up 1 day, &amp;nbsp;3:37, &amp;nbsp;6 users, &amp;nbsp;load average: 1.37, 0.34, 0.11&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Tasks: 101 total, &amp;nbsp; 4 running, &amp;nbsp;97 sleeping, &amp;nbsp; 0 stopped, &amp;nbsp; 0 zombie&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Cpu(s): &amp;nbsp;7.1%us, 16.7%sy, &amp;nbsp;0.0%ni, &amp;nbsp;6.2%id, 67.3%wa, &amp;nbsp;0.4%hi, &amp;nbsp;2.4%si, &amp;nbsp;0.0%st&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Mem: &amp;nbsp; &amp;nbsp;775064k total, &amp;nbsp; 767664k used, &amp;nbsp; &amp;nbsp; 7400k free, &amp;nbsp; 514236k buffers&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Swap: &amp;nbsp; 136544k total, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0k used, &amp;nbsp; 136544k free, &amp;nbsp; 102744k cached&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; PID USER &amp;nbsp; &amp;nbsp; &amp;nbsp;PR &amp;nbsp;NI &amp;nbsp;VIRT &amp;nbsp;RES &amp;nbsp;SHR S %CPU %MEM &amp;nbsp; &amp;nbsp;TIME+ &amp;nbsp;COMMAND&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;8859 root &amp;nbsp; &amp;nbsp; &amp;nbsp;18 &amp;nbsp; 0 &amp;nbsp;1788 &amp;nbsp;524 &amp;nbsp;448 R &amp;nbsp; 46 &amp;nbsp;0.1 &amp;nbsp; 0:21.25 cat&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;8860 root &amp;nbsp; &amp;nbsp; &amp;nbsp;18 &amp;nbsp; 0 &amp;nbsp;1792 &amp;nbsp;524 &amp;nbsp;448 R &amp;nbsp; 41 &amp;nbsp;0.1 &amp;nbsp; 0:18.83 cat&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;229 root &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;9 &amp;nbsp;0.0 &amp;nbsp; 0:01.54 kswapd0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;3695 root &amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; 0 &amp;nbsp;1864 &amp;nbsp;700 &amp;nbsp;616 S &amp;nbsp; &amp;nbsp;3 &amp;nbsp;0.1 &amp;nbsp; 0:16.00 hald-addon-stor&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;4580 root &amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; 0 95916 &amp;nbsp;14m &amp;nbsp;11m S &amp;nbsp; &amp;nbsp;3 &amp;nbsp;1.9 &amp;nbsp; 0:36.44 main-menu&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;4552 root &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; 0 &amp;nbsp;101m &amp;nbsp;24m &amp;nbsp;17m S &amp;nbsp; &amp;nbsp;2 &amp;nbsp;3.2 &amp;nbsp; 0:13.44 nautilus&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; 13 root &amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;1 &amp;nbsp;0.0 &amp;nbsp; 0:00.70 kblockd/0&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;4270 root &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; 0 &amp;nbsp;146m &amp;nbsp;12m 5716 S &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1.7 &amp;nbsp; 1:01.66 X&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;4536 root &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; 0 29012 9688 7896 S &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1.2 &amp;nbsp; 0:05.47 gnome-settings-&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;4578 root &amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; 0 18136 5500 4124 S &amp;nbsp; &amp;nbsp;1 &amp;nbsp;0.7 &amp;nbsp; 0:14.87 gnome-power-man&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;8861 root &amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; 0 &amp;nbsp;2236 1036 &amp;nbsp;780 R &amp;nbsp; &amp;nbsp;1 &amp;nbsp;0.1 &amp;nbsp; 0:00.64 top&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; 14 root &amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp;-5 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;1 &amp;nbsp;0.0 &amp;nbsp; 0:00.49 kblockd/1&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;4575 root &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; 0 95736 &amp;nbsp;13m &amp;nbsp;10m S &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1.8 &amp;nbsp; 0:07.39 application-bro&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;3131 root &amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; 0 &amp;nbsp;4692 3244 1444 S &amp;nbsp; &amp;nbsp;1 &amp;nbsp;0.4 &amp;nbsp; 0:34.57 hald&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;4586 root &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; 0 93868 &amp;nbsp;11m 9796 S &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1.6 &amp;nbsp; 0:06.62 mixer_applet2&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;228 root &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 S &amp;nbsp; &amp;nbsp;0 &amp;nbsp;0.0 &amp;nbsp; 0:00.95 pdflush&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
If the workload is getting too high, you need to find out what is happening. To do this, you have to look at the CPU line(s). You will see no less than eight different parameters, and of these, only three really matter. First is the &quot;us&quot; parameter. This indicates the amount of time your system is busy handling requests that were made in user space. If a task is not in user space, it is a high-privileged task that runs in system space, which you can see reflected in the &quot;sy&quot; parameter. In kernel space, processes can communicate directly to the drivers. Therefore, you should worry more if your system gives a high load in system space. The third parameter that is important in the CPU line is &quot;wa.&quot; This stands for waiting, and indicates the amount of time your system waits for I/O-devices. A high parameter here indicates a problem on the I/O-channel, normally this is a hard disk that is too slow or a misconfigured network.&lt;br /&gt;
&lt;br /&gt;
The second listing example shows that the system is way too busy waiting for I/O. This is far too common, many times system performance problems are related to slow I/O devices. One solution is to install a faster hard drive, but before doing that, it is a good idea to check the BIOS of your server and see if there are parameters that you can tune. One of the most important candidates for that, is the write cache parameter. By writing data to write cache before writing it to the disk platters themselves, you can dramatically reduce waiting times. Since write cache is about 1,000 times as fast as the hard disk, chances are that you can win a lot by enabling this feature.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Use top to reveal memory efficiency on Linux servers&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Apart from the information on how busy your system&#39;s CPU is, top also shows you how memory-efficient your server is. You can find information about this in the lines that start with Mem: and Swap:. Let&#39;s start discussing swap. This is RAM that is emulated on the hard drive that your computer should never use. There are some exceptions though: if your server runs Oracle, SAP or any other specific application that is built to use swap. But normally, Linux starts swapping only if it is totally out of normal memory. In an exception, your server could pre-allocate some swap so that it can use it faster if it&#39;s needed. But in most cases, you should install new RAM on a server that starts swapping.&lt;br /&gt;
&lt;br /&gt;
After you have verified that your system isn&#39;t swapping, you should find out what it is doing with available memory. To understand memory, you should know that Linux uses memory quite efficiently. If there&#39;s no real need for memory to service processes, it will be used as read cache or write buffers. The read cache contains files that were recently read from your computer&#39;s hard drive. The kernel just keeps them in RAM, because you might need them again and if you do, it&#39;s a lot faster to serve these files from RAM than from hard disk. The write buffers on the other hand, are used as a waiting room for your server&#39;s hard drive. Instead of offering data directly to the hard drive, the operating system places them in the write buffers where they can wait until the hard disk decides it has time to flush these write buffers (e.g., writes them to disk). This also gives you a performance benefit.&lt;br /&gt;
&lt;br /&gt;
The nice thing about read cache and write buffers is that the operating system can make them available instantaneously when it needs memory. Therefore, you should add the read cache and write buffers to the total amount of available memory. A nice way of doing this, is by using the &lt;b&gt;&lt;i&gt;free -m&lt;/i&gt;&lt;/b&gt; command. On the &lt;b&gt;&lt;i&gt;+/&lt;/i&gt;&lt;/b&gt;&lt;b style=&quot;font-style: italic;&quot;&gt;- buffers/cache&lt;/b&gt; line, you can see how much free memory your computer really has.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;host:~ # free -m&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;total &amp;nbsp; &amp;nbsp; &amp;nbsp; used &amp;nbsp; &amp;nbsp; &amp;nbsp; free &amp;nbsp; &amp;nbsp; shared &amp;nbsp; &amp;nbsp;buffers &amp;nbsp; &amp;nbsp; cached&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Mem: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;756 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 746 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 595 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 40&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;-/+ buffers/cache: &amp;nbsp; &amp;nbsp;110 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;646&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Swap: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;133 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;133&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
As you can see in this listing, at first sight it looks as if this server almost has no more available memory, but if you know that buffers can be flushed immediately, you can see that it has largely enough available memory.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Determining active processes on a Linux server&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The last interesting part of top is where it shows the most active process on your server. This is not hard to determine: the most active process is listed first on the process list. If this process uses too much system resources, top offers some options to handle it. You can terminate it by pressing the &lt;b&gt;&lt;i&gt;k-key&lt;/i&gt;&lt;/b&gt; from the top interface. Top will then ask you what signal you want to send to this process. You should always try signal 15 first, this represents the nice way of asking the process to please stop its activity. If that doesn&#39;t work, use signal 9, which just terminates the process without further waiting.&lt;br /&gt;
&lt;br /&gt;
Another way of taming a process, is by &quot;&lt;b&gt;renicing&lt;/b&gt;&quot; it – i.e., adjust the priority the process is using. To do this, press the&lt;b&gt;&lt;i&gt; r-key&lt;/i&gt;&lt;/b&gt; from the top interface. By giving a process a negative nice value, you increase the priority with regard to other processes. By assigning a positive nice value, you give more room for the other processes. The values you can use are between -20 and 19. It&#39;s a good idea not to assign the value of -20. By doing this, you would give the highest possible priority to a process, thus allowing it to leave no time for the other processes (if it is a busy process).</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/3270677843648355547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/understanding-linux-system-performance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/3270677843648355547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/3270677843648355547'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/understanding-linux-system-performance.html' title='Understanding Linux system performance management using top'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-7720952810255931543</id><published>2010-10-27T11:10:00.001-06:00</published><updated>2010-10-27T17:23:59.789-06:00</updated><title type='text'>Managing Samba (Part 1 of 6): Windows network identity basics</title><content type='html'>In heterogeneous IT environments, Samba has to deal with two entirely dissimilar environments: the Unix or Linux host on which Samba is being run as a service and a Windows network that is made up of workstations and servers. Understanding Windows networking identity basics can make Samba management a lot easier, and this article -- part one of a series – offers my insights on that subject.&lt;br /&gt;
&lt;br /&gt;
Microsoft Windows workstations users practice the browsing of network file and print resources as the natural way to achieve daily tasks, yet few are aware of how this works. The ability to browse network resources via the Microsoft Windows Explorer is an expected capability. When this ability is impaired, the user&#39;s frustration is readily elevated. What a user considers as simply the process of browsing is comprised of a large number of complex processes, all of which must function correctly so that the user can experience expected behavior.&lt;br /&gt;
&lt;br /&gt;
The browsing of network resources is possible by way of creating:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Special broadcast announcements made by Windows network clients and servers.&lt;/li&gt;
&lt;li&gt;Machines -- selected through an election mechanism and called browse masters -- on the network that listen for the special broadcast messages.&lt;/li&gt;
&lt;li&gt;Name resolution processes that permit the translation of a NetBIOS machine name to a TCP/IP address.&lt;/li&gt;
&lt;li&gt;Establishment of a connection to a Windows file share.&lt;/li&gt;
&lt;li&gt;All these mechanisms must work in harmony; otherwise, the expected user experience is lost.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
The establishment of a connection is the vital step that enables access to a remote file. The Windows client provides a user name and password as part of the data request to create the network connection. The user name and password may both be empty (the null account), or the password may be empty (null password).&lt;br /&gt;
&lt;br /&gt;
The use of the null account is common when creating a connection to the IPC$ share on a target Windows networking server like a Samba server. The IPC$ share is used by the network client to obtain the list of resources (shares and printers) that are available on the server. When a resource has been selected, a connection is created between the client and the server to enable the resource (share or printer) to be used by the network client. The connection request is refused if the credentials that are provided by the client are refused by the server.&lt;br /&gt;
&lt;br /&gt;
This article is primarily concerned with the behavior of a Samba server and does not deal with Microsoft Windows network servers.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Samba authentication&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The authentication methodology that is used by a Samba server depends on how it has been configured, as well as whether or not Winbind is in use. If Winbind is in use, smbd, the Samba process that performs all network connection handling, will ask Winbind to process the authentication request for the network connection setup request. If Winbind is able to perform authentication, handling it will return to the smbd process that called it either a pass or fail.&lt;br /&gt;
&lt;br /&gt;
If Winbind is not able to resolve the validity of the network user&#39;s credentials or is not available -- for example, it is not running -- the responsibility for determining whether or not the network connection request should proceed is handled by smbd. In this case, smbd will attempt to look up the user in the passdb back end that has been specified in the &lt;b&gt;&lt;i&gt;smb.conf&lt;/i&gt;&lt;/b&gt; file. If the &lt;b&gt;&lt;i&gt;smb.conf &lt;/i&gt;&lt;/b&gt;file does not specify a passdb back end, smbd will use the default passdb back end (smbpassswd). The user name and password are validated against the encrypted credentials that are stored in this back-end database.&lt;br /&gt;
&lt;br /&gt;
As I said earlier in this article, Samba has to deal with two dissimilar environments: the Unix or Linux host, where Samba runs as a service, and the Windows network of workstations and servers. Samba must obey the rules that are imposed by both environments. The authentication of Windows network operations requires access to the Microsoft encrypted passwords that are stored in Samba&#39;s own password back end.&lt;br /&gt;
&lt;br /&gt;
Samba refers to this as part of the Samba security account manager (Samba SAM) data. The SAM information database (passdb back end) contains all the Windows-specific account information that is not used by the Unix/Linux environment.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;User/group name and security identifier handling&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
When the connection to the share has been established, further access to shared network resources requires an user identifier (UID) and a group identifier (GID) on the Unix or Linux host server for the remote Windows user. This requires fully functional forward and reverse name to Unix or Linux identifier resolution. This requirement exists because a Unix or Linux host requires a UID and GID pair to determine access rights that are applicable to the remote Windows network user for all Unix file system access operations.&lt;br /&gt;
&lt;br /&gt;
The windows user has the capacity to modify file security settings and access controls using the Windows Explorer. For this to function correctly, there needs to be a reliable and reproducible method for resolving user names to the matching Windows system identifier (SID). The reverse is also necessary. The Windows user SID is critical to the use of a tool, such as Windows Explorer, for the handling (setting and reporting) of file and directory security settings. This requires the ability to map a UID or a GID from the Unix/Linux file system to a unique Windows SID, and demands a consistent mapping of the Unix/Linux user name or group name to a Window user name or group name. The mapping must be unambiguous.&lt;br /&gt;
&lt;br /&gt;
Every Microsoft Windows operating system has a unique machine security identifier (the machine SID). Likewise, a Microsoft Windows security domain also has its domain SID. User and group accounts that are created within either context are assigned a sequential security identifier that is relative to the security context. This identifier is known as the relative identifier (RID) and is added to the end of the SID for the security context within which it has been created. This means that when a user account is created for a user called adaniel on a collection of Windows NT/200x/XP machines, each account will have its own unique user SID. The user SID thus being made up of the machine SID concatenated to the user RID.&lt;br /&gt;
&lt;br /&gt;
Windows accounts (user, group, machine, trust, etc.) are assigned a RID. This is done automatically as an account is created. Samba produces the RID algorithmically. The Unix operating system uses a separate name space for the UIDs and GIDs, but Windows allocates the RID from a single name space.&lt;br /&gt;
&lt;br /&gt;
A Windows user and a Windows group cannot have the same RID. Just as the Unix user root has the UID=0, the Windows administrator has the well-known RID=500. The RID is concatenated to the Windows domain SID, so administrator account for a domain that has the above SID will have the user SID S-1-5-21-726309263-4128913605-1168186429-500. Outside of the well-known accounts that have a globally consistent RID, the RIDs are allocated starting at RID=1000. The RID is appended to the SID of the machine with the result that every account in the Windows networking world will have a globally unique security identifier.&lt;br /&gt;
&lt;br /&gt;
In the Windows environment, user, group and trust accounts are all allocated a sequential number from the same name space (the RID). In the Unix/Linux environment, the UID and GID are independent entities providing each its own name space.&lt;br /&gt;
&lt;br /&gt;
Samba obeys the security constraints that are normative to the host operating system on which it is running, as well as that of the Windows clients it serves. This means that the translation (or mapping) of Windows users and groups, Windows SIDs, Unix UIDs and GIDs, and Unix account names must be possible in a manner that is entirely unambiguous at all times. This is an important matter that Unix administrators often overlook.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Samba SAM information location&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Information that is specific to the local Samba server is stored in the file&lt;b&gt;&lt;i&gt; /etc/samba/secrets.tdb&lt;/i&gt;&lt;/b&gt;. The domain SID, as well as the local server SID, is stored in this file. When Samba-3 is used with the LDAP passdb back end, the LDAP administrator password is also stored in the secrets file. When Samba is a domain member server, the domain membership account secret password is also stored in the secrets file.&lt;br /&gt;
&lt;br /&gt;
Where the tdbsam passdb back end is used, user account information is stored in the (default) file called &lt;b&gt;&lt;i&gt;/etc/samba/passdb.tdb&lt;/i&gt;&lt;/b&gt; and contains the extended Samba SAM account information that can also be stored in an LDAP directory in the event that the ldapsam passdb back end is chosen.&lt;br /&gt;
&lt;br /&gt;
Samba-3 can make concurrent use of multiple passdb back ends, making Samba-3 highly scalable, thereby permitting it to meet the needs of small, as well as very large, sites.&lt;br /&gt;
&lt;br /&gt;
Unix groups can be made available to Windows users by creating a group mapping. The group mapping is part of the Samba SAM account information data and is stored either in the file &lt;b&gt;&lt;i&gt;/var/lib/samba/group_mapping.tdb&lt;/i&gt;&lt;/b&gt; (when using tdbsam) or in an LDAP directory (ldapsam).&lt;br /&gt;
&lt;br /&gt;
User rights and privilege information, together with domain access controls, are stored in the file &lt;b&gt;&lt;i&gt;/var/lib/samba/account_policy.tdb&lt;/i&gt;&lt;/b&gt;. ACL access controls on shares are stored in the &lt;b&gt;&lt;i&gt;/var/lib/samba/share_info.tdb&lt;/i&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
As of Samba version 3.0.21, the account policy information will be stored in the LDAP directory when the primary passdb back end specified is the ldapsam. Samba versions earlier than 3.0.21 did not replicate policy information via the LDAP directory, thus making it necessary to manage policy settings on all domain controllers. Version 3.0.21 automatically replicates policy information to all domain controllers (as happens with Windows NT4).&lt;br /&gt;
&lt;br /&gt;
The tdb files store binary hashed data, the contents of which can be dumped to a plain ASCII format using the tdbdump utility. For example, the content of the secrets.tdb file can be exposed by executing:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;linux:/etc/samba # tdbdump secrets.tdb&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;{&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;key = &quot;SECRETS/SID/LINUX&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;data =&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&quot;\01\04\00\00\00\00\00\05\15\00\00\000\DE\06\F4\FB\C0\AD\D3d\D7\1E\9C\00&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;}&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Summary&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This article has begun the process of untying the knot that protects those secrets of Samba domain administration. It has been established that the security identifiers differ greatly on Samba host platforms from that of the Microsoft Windows world. A brief explanation has been given to show how Samba manages security identifier interoperability.&lt;br /&gt;
&lt;br /&gt;
The next article will compare Windows and Samba user rights and privilege management. Now that some of the darker secrets regarding Linux and Windows security identifiers have been covered, we are ready to move on to explore the tools that can be used to manage make efficient use of them.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;Click here&lt;/u&gt;&lt;/i&gt; to go back to the introduction to this series.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/7720952810255931543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-1-of-6-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/7720952810255931543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/7720952810255931543'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/managing-samba-part-1-of-6-windows.html' title='Managing Samba (Part 1 of 6): Windows network identity basics'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-6942524416563067473</id><published>2010-10-26T16:04:00.001-06:00</published><updated>2010-10-27T15:32:01.056-06:00</updated><title type='text'>Keep an eye on Linux processes with ps</title><content type='html'>On Microsoft Windows, the Task Manager is responsible for reporting on and managing the running processes and applications on a server. Linux servers have a Task Bar (or equivalent) when they are viewed from desktops such as GNOME and KDE, but the main tools for process management are command-line ones. Here we&#39;ll discuss how to see what&#39;s running on a Linux server.&lt;br /&gt;
&lt;br /&gt;
On Linux, processes have owners. Any user can view all the current processes, but only the root user has full management of those processes. On Linux every process runs in its own memory space and can&#39;t accidentally overwrite other processes. A process that crashes or dies due to a bug also can&#39;t ruin any other process. It&#39;s still possible that a process may cope poorly with the loss of another process on which it depends. The Linux kernel itself is not a process; it is special. It is the program that brings into being a playpen inside of which all processes must play.&lt;br /&gt;
&lt;br /&gt;
The central tool used to display processes is the command line tool &quot;&lt;b&gt;&lt;i&gt;ps&lt;/i&gt;&lt;/b&gt;&quot;. Type &quot;&lt;b&gt;&lt;i&gt;man ps&lt;/i&gt;&lt;/b&gt;&quot; for full details. &quot;&lt;b&gt;&lt;i&gt;ps&lt;/i&gt;&lt;/b&gt;&quot; stands for &quot;&lt;b&gt;&lt;i&gt;process status&lt;/i&gt;&lt;/b&gt;&quot;. When run, it queries the Linux kernel for the current state of the machine, and based on the snapshot returned, outputs a formatted report. The plainest use of ps shows processes owned by the current Linux user.&lt;br /&gt;
&lt;br /&gt;
In the normal output, CMD states the name of the program that the process is a currently running example of, and TIME is the hours, minutes and seconds of CPU time consumed by that program during that run. PID is the unique identifier for that process.&lt;br /&gt;
&lt;br /&gt;
To see the processes owned by another user, try:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ps -u fred&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
where &quot;fred&quot; is a Linux &lt;b&gt;&lt;i&gt;/etc/passwd&lt;/i&gt;&lt;/b&gt; user name. For more detail, the long (&lt;b&gt;&lt;i&gt;-l&lt;/i&gt;&lt;/b&gt;) or full (&lt;b&gt;&lt;i&gt;-f&lt;/i&gt;&lt;/b&gt;) options can be used; but the same processes are discovered. Be careful concatenating options; &quot;&lt;b&gt;&lt;i&gt;ps -lufred&lt;/i&gt;&lt;/b&gt;&quot; is &quot;&lt;b&gt;&lt;i&gt;ps -l -u fred&lt;/i&gt;&lt;/b&gt;&quot;, but &quot;&lt;b&gt;&lt;i&gt;ps -ulfred&lt;/i&gt;&lt;/b&gt;&quot; is &quot;&lt;b&gt;&lt;i&gt;ps -u lfred&lt;/i&gt;&lt;/b&gt;&quot;&lt;br /&gt;
&lt;br /&gt;
Each process has both an identifying process ID (a PID), and a parent process ID (a PPID). The parent process is the process that was used to &quot;spawn&quot; (to start) the other process. Usually, the PPID is a command-line shell such as ksh or bash, but it can also be a server such as httpd or inetd.&lt;br /&gt;
&lt;br /&gt;
PID numbers start at one and go up, so processes started more recently have higher numbers. If a process has PPID=1, that means it was either started by &quot;init,&quot; the first process that runs when Linux starts up, or (rarely) it has partially failed and has lost its parent process. Such part-failed processes are called &quot;zombies&quot;.&lt;br /&gt;
&lt;br /&gt;
A very common use of ps is the command:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ps -ef&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
which reports every process running, regardless of owner. Also, &lt;b&gt;&lt;i&gt;ps&lt;/i&gt;&lt;/b&gt; output is highly customizable; the &lt;b&gt;&lt;i&gt;-o&lt;/i&gt;&lt;/b&gt; option can be used to report exactly the columns you want. Be sure to set and export the COLUMNS environment variable if you want a very wide report, eg:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;COLUMNS=300; export COLUMNS&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Finally, the &lt;b&gt;&lt;i&gt;-H&lt;/i&gt;&lt;/b&gt; option, usually used with &lt;b&gt;&lt;i&gt;-e&lt;/i&gt;&lt;/b&gt;, shows all the processes stacked in a Windows Explorer-like hierarchy. This gives you visual cues (indenting) showing relationships between PPIDs and PIDs.&lt;br /&gt;
&lt;br /&gt;
Running &lt;b&gt;&lt;i&gt;ps&lt;/i&gt;&lt;/b&gt; hundreds of times a second is bad for general performance, because the kernel must spend time reporting on itself. To watch the process list change in real time, most Linux versions include the program &#39;&lt;b&gt;&lt;i&gt;top&lt;/i&gt;&lt;/b&gt;&#39;. You&#39;ll find that &lt;b&gt;&lt;i&gt;top&lt;/i&gt;&lt;/b&gt; acts like &lt;b&gt;&lt;i&gt;ps&lt;/i&gt;&lt;/b&gt; repeated at fastest once a second. It sorts the output so that the most CPU-intensive options are, well, at the top. The sort order is configurable. Beware that top (and many other programs) expect that you are using a quality terminal emulation in your command window. Usually xterm is enough. Microsoft Window&#39;s simple telnet client is too basic. Try installing the free Windows tool PuTTY if you must telnet to Linux from Windows.&lt;br /&gt;
&lt;br /&gt;
Finally, &lt;b&gt;&lt;i&gt;ps&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;top&lt;/i&gt;&lt;/b&gt; do their job by exploiting a special interface to the kernel. Many GUI and command-line tools exist that also exploit this interface. For a quick hands-on assessment of a server&#39;s condition, simple &lt;b&gt;&lt;i&gt;ps&lt;/i&gt;&lt;/b&gt; is usually the safest way to go.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/6942524416563067473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/keep-eye-on-linux-processes-with-ps.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6942524416563067473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6942524416563067473'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/keep-eye-on-linux-processes-with-ps.html' title='Keep an eye on Linux processes with ps'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-3832587217546932420</id><published>2010-10-26T15:35:00.001-06:00</published><updated>2010-10-27T15:32:01.069-06:00</updated><title type='text'>How to manage software on Ubuntu Server with &quot;aptitude&quot; and &quot;apt-get&quot;</title><content type='html'>If you are used to RPM-based Linux-distributions such as Red Hat and SUSE, it is quite a shock getting used to package management on Ubuntu Server. The most difficult part is the layered organization of Ubuntu package management services. Nevertheless, in many ways Ubuntu offers a much easier way to manage packages based on the Debian package format. Understanding how Ubuntu Package management works allows you to do your work as a Ubuntu Server administrator much more efficiently, and even update your system in one single command. In this article we&#39;ll explain how it works.&lt;br /&gt;
&lt;br /&gt;
Ubuntu uses the same package management solutions as Debian. Package management on Ubuntu Server is based on a database that keeps track of all software packages that are installed. The most fundamental of all is the dpkg-database, which is based directly on the Debian package management utility. On top of that sits the apt database which is stored in /var/lib/apt. To manage packages in this database, you can use the &quot;apt-get&quot; command or the &quot;aptitude&quot; command. Both do more or less the same. If a graphical user interface is installed, the Synaptic utility can be used as well. In this article you&#39;ll read how to work with these tools.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Managing software repositories&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Apart from the database that manages packages that are installed on your server, there is also the software repository as a second fundamental component that you need for package management. These repositories are basically lists of installation sources. One such installation source is the cd that you have probably used to install Ubuntu Server. Other sources are added automatically when installing Ubuntu Server. A list of all installation sources is found in the configuration file &lt;b&gt;&lt;i&gt;/etc/apt/sources.list&lt;/i&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Since these sources refer to Internet sites as well as local installation sources, they help you in keeping your server up to date. The &quot;apt-get&quot; command always uses this list of sources before installing new software. To make sure that the list is up to date, you have to use the &quot;apt-get update&quot; command. This makes sure that the indexes that your server keeps locally are updated so that they know about new software packages that have become available. Once the indexes are updated this way, you can use &quot;apt-get upgrade&quot; to upgrade packages on your server to their latest versions or &quot;apt-get install package-name&quot; which will install the most recent version of the package that you want to use.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Managing packages with &quot;aptitude&quot;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Another command that works on the same package database, is &quot;aptitude&quot;. This is not so much a command that you would use to install or upgrade packages, but more a command that is used for package management. You would use this command, for example, to search for packages that match a given keyword, e.g.: &quot;&lt;b&gt;&lt;i&gt;aptitude search xen&lt;/i&gt;&lt;/b&gt;&quot;. This displays a list of all packages that match the description xen. The command would give a result like in listing 1.&lt;br /&gt;
&lt;br /&gt;
Listing 1: Searching packages with &quot;aptitude&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;user@host:~$ aptitude search xen&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; ubuntu-xen-desktop &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - Xen software for running on servers.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; ubuntu-xen-server &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Xen software for running on servers.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-doc-2.6.16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Linux kernel specific documentation&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-docs-3.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- documentation for XEN, a Virtual Mac&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-headers &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-headers-2.6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-headers-2.6.16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Header files related to Linux kernel&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-headers-2.6.19-4 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Common header files for Linux 2.6.19&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-headers-2.6.19-4-gener&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Common header files for Linux 2.6.19&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-headers-2.6.19-4-serve&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Common header files for Linux 2.6.19&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-hypervisor &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-hypervisor-3.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-hypervisor-3.0-i386 &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- The Xen Hypervisor for i386&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-hypervisor-3.0-i386-pa&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- The Xen Hypervisor for i386 (pae ena&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-hypervisor-i386 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-hypervisor-i386-pae &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-image-2.6.19-4-generic&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Linux 2.6.19 image on PPro/Celeron/P&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-image-2.6.19-4-server &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Linux xen 2.6.19 image on x86.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-ioemu-3.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- XEN administrative tools&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-restricted-modules-2.6&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Non-free Linux 2.6.17 modules on x86&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-source &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-source-2.6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-source-2.6.16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Linux kernel source for version 2.6.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-tools &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- Tools to manage debian XEN virtual s&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xen-utils &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-utils-3.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- XEN administrative tools&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xen-utils-common &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- XEN administrative tools - common fi&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xengine &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- A benchmark program for the X Window&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;p &amp;nbsp; xenman &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;- A graphical Xen management tool&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;v &amp;nbsp; xenx-doc-2.6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
From the list of all these packages, you can next use the command &quot;&lt;b&gt;&lt;i&gt;aptitude show&lt;/i&gt;&lt;/b&gt;&quot; to get more information about a package. For example, use &quot;&lt;b&gt;&lt;i&gt;aptitude show xen-source&lt;/i&gt;&lt;/b&gt;&quot; to get a description of the xen-source package if it is already installed, or use &quot;&lt;b&gt;&lt;i&gt;apt-get install xen-source&lt;/i&gt;&lt;/b&gt;&quot; to install it now.&lt;br /&gt;
&lt;br /&gt;
If you don&#39;t like to manage packages from the command line, there is good news. The aptitude utility can work in menu mode as well, but to do that you must make sure that the right terminal setting is used. To do this, first type export TERM=vt100. Next run &quot;&lt;b&gt;&lt;i&gt;aptitude&lt;/i&gt;&lt;/b&gt;&quot; again, and you&#39;ll see the interface from Figure 1. From this interface you can check which packages are installed and which are not from an intuitive menu interface.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;GUI package management&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
If managing packets from the console using &quot;&lt;b&gt;&lt;i&gt;apt-get&lt;/i&gt;&lt;/b&gt;&quot; or &quot;&lt;b&gt;&lt;i&gt;aptitude&lt;/i&gt;&lt;/b&gt;&quot; is not ideal for you, you might want to do it from a graphical user interface instead. One of the tools that comes with the graphical interface is the Synaptic package manager, which is based on the apt database as well. It offers an intuitive mouse-driven interface to help you install and manage software packages.&lt;br /&gt;
&lt;br /&gt;
In Synaptic, the &quot;Sections&quot; button is a good starting point. This button allows you to see all available software, organized by software category. To see what&#39;s inside a category, click it, and in the right part of the Synaptic window you&#39;ll see a list of available packages. After clicking an individual package, you&#39;ll see a description of the package, allowing you to see exactly what is in the package. Next, select the &quot;&lt;b&gt;Mark for Installation&lt;/b&gt;&quot; option and click &quot;&lt;b&gt;Apply&lt;/b&gt;.&quot; This will bring up the window that you see in Figure 3, asking you if you really want to install this package. From this window, click &quot;&lt;b&gt;Apply&lt;/b&gt;&quot; to start the package&#39;s installation.&lt;br /&gt;
&lt;br /&gt;
Another useful option from the Synaptic interface is the &quot;&lt;b&gt;Search&lt;/b&gt;&quot; feature. It works very easily: Click &quot;&lt;b&gt;Search&lt;/b&gt;&quot;, and in the window that pops up, select the software that you are looking for. Click &quot;&lt;b&gt;Search&lt;/b&gt;&quot; again and you&#39;ll see a list with all matching packages in it. Next, mark them for installation and click &quot;&lt;b&gt;Apply&lt;/b&gt;&quot; if you really want to use these packages.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
For first time users, the Ubuntu server package management utilities are quite intimidating. The most important reason for that is that a layered architecture with related commands is used to manage software on your server. The most important system is based on the apt package database. In this article you have learned how to use the commands &quot;&lt;b&gt;&lt;i&gt;apt-get&lt;/i&gt;&lt;/b&gt;&quot; and &quot;&lt;b&gt;&lt;i&gt;aptitude&lt;/i&gt;&lt;/b&gt;&quot; to perform package management from the command line. You&#39;ve also seen how the Synaptic package manager can make package management easier if you are using a graphical environment.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/3832587217546932420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/how-to-manage-software-on-ubuntu-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/3832587217546932420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/3832587217546932420'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/how-to-manage-software-on-ubuntu-server.html' title='How to manage software on Ubuntu Server with &quot;aptitude&quot; and &quot;apt-get&quot;'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-4426360297932205026</id><published>2010-10-26T15:27:00.001-06:00</published><updated>2010-10-27T15:32:01.076-06:00</updated><title type='text'>Linux/Unix commands: How to get copy, conversion power with dd</title><content type='html'>System administrators often have to copy data around. Copying and converting ordinary data is easily accomplished with the Linux command called cp. However, if the data is not ordinary, cp is not powerful enough. The needed power can be found in the dd command, and here are some ways to put that power to good use.&lt;br /&gt;
&lt;br /&gt;
The dd command handles convert-and-copy tasks. Obviously, &quot;cc&quot; would have been a better name, but there already was a command with that name when dd was invented. It doesn&#39;t matter since it&#39;s a cool command.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Cloning a hard drive with dd&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The dd command doesn&#39;t just copy files; it copies blocks, too. As a simple example, I&#39;ll show you how to clone your entire hard drive.&lt;br /&gt;
&lt;br /&gt;
Assuming that /dev/sda is the drive that you want to clone, and /dev/sdb is an empty drive that can be used as the target, using the dd command rather easy:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;dd if=/dev/sda of=/dev/sdb&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
In that example, dd is used with only two parameters: if, which is used to specify an input file, and of, which is used to specify the output file. In this case, both input and output files are device files. Wait until the command is finished, and you will end up with an exact copy of the original hard drive.&lt;br /&gt;
&lt;br /&gt;
In the latter example, the contents of a device were copied to another device. A slight variation to that is the way that dd is used to clone a DVD or CD-ROM and write it to an ISO file. If your optical drive can be accessed via /dev/cdrom, then you can clone the optical disk using:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;dd if=/dev/cdrom of=/tmp/cdrom.iso&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
You can also mount that ISO-file using:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;b&gt;&lt;i&gt;mount -o loop /tmp/cdrom.iso /mnt&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;Next, you can access the files in the ISO-file from the directory where the ISO is mounted.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Creating a backup of the Master Boot Record&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So far, we have used dd to perform tasks that can be done with other utilities as well. Now, we can go beyond that. In the following example, let&#39;s create a backup of the Master Boot Record (MBR).&lt;br /&gt;
&lt;br /&gt;
Copy the first 512 bytes of your hard drive, which contains the MBR, to a file. For instance, you could do this with the command&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;dd if=/dev/sda of=/boot/mbr_backup bs=512 count=1&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
In this scenario, two new parameters are used:&lt;br /&gt;
&lt;br /&gt;
First, there&#39;s the parameter &lt;b&gt;&lt;i&gt;bs=512&lt;/i&gt;&lt;/b&gt;, which specifies that a blocksize of 512 bytes should be used.&lt;br /&gt;
Next, the parameter &lt;b&gt;&lt;i&gt;1&lt;/i&gt;&lt;/b&gt; is used to indicate that only one such block has to be copied. Without that parameter, you would copy your entire hard drive.&lt;br /&gt;
The backup copy of your MBR may be useful if, some day, you can&#39;t boot your server anymore because of a problem in the MBR. In case that happens, just boot from a rescue disk and use the command:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;dd if=/boot/mbr_backup of=/dev/sda bs=446 count=1&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
In this restore command, only 446 bytes are written back. This is because you may have changed the partition table since you&#39;ve created the backup. By writing back only the first 446 bytes of your backup file, you don&#39;t overwrite the original partition table, which is between bytes 447 and 511.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Extending swap space&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In the last example of how dd can save your life, I&#39;ll show you how to extend your swap space by adding a swap file.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s say that you&#39;re alerted at 3 a.m. by a message saying your server is about to run out of memory entirely, due to an undiscovered memory leak. All you have to do is create an empty file and specify that it should be added to the swap space.&lt;br /&gt;
&lt;br /&gt;
Creating this empty file is an excellent task for dd:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;dd if=/dev/zero of=/swapfile bs=1024 count=1000000&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
This would write a file of one gigabyte, and that can be added to the swap space using:&lt;br /&gt;
&amp;nbsp;&lt;b&gt;&lt;i&gt;mkswap /swapfile&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;swapon /swapfile&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In this article, you&#39;ve learned how to do some basic troubleshooting using the dd utility. As you have read, dd is a very versatile utility that goes far beyond the capabilities of ordinary copy tools like cp. Its abilities to work with blocks instead of files are especially valuable.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/4426360297932205026/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/linuxunix-commands-how-to-get-copy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/4426360297932205026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/4426360297932205026'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/linuxunix-commands-how-to-get-copy.html' title='Linux/Unix commands: How to get copy, conversion power with dd'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-6602881591047351810</id><published>2010-10-26T15:19:00.001-06:00</published><updated>2010-10-27T15:32:01.082-06:00</updated><title type='text'>Using grep and sed to find and replace</title><content type='html'>This article covers two beneficial Linux tools, grep and sed. If searching for or handling text, grep and sed can increase your efficiency with Linux bash scripting and configuration files. We&#39;ll learn how to use these commands and get some helpful tips, too.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Using Grep&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Need to find a single matching line in a 300 page script or a large configuration file that you&#39;ve customized? Don&#39;t have the time to search line by line to find that single bug that is halting your system when trying to start the service? You can search for a string quickly using grep.&lt;br /&gt;
&lt;br /&gt;
You can search with grep (an acronym for searching globally for lines matching the regular expression, and print them) many of the files on a Linux machine. When you give it a list of files to read, it will search for lines of text that match the expressions you&#39;re looking for and, if it find any, it will output the pieces you want. Just think of as a grip: using grep is a great way to grab a hold of specific lines or files. This command line utility was originally designed for Unix systems.&lt;br /&gt;
&lt;br /&gt;
For example, let&#39;s say we have a list of numbers in a file, numlist.txt, and we want to see if the number 8723 is in the list without searching for hours. Using grep can easily find the string in the following command line:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;grep –i 8723 numlist.txt&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If we get an output of 8723, then it is in the list. If we do not get an output, it is not there. The tool will print the whole line where the text string is found. If the list contained 8723 297r, we would get:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[root@tower root]# grep 8723 numlist.txt 8723 297r&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[root@tower root]#&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Grep is case sensitive by default. To disable this, use the –i flag.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s something useful in a daily RHEL system checkup. Say you need to find out which version of sendmail rpm you installed. To list which rpm packages are installed on the system, you enter the following:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;rpm –qa&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If you have a system like mine, you have just too many packages to sort through. It might take forever to go through them line by line to find the package you&#39;re looking for. Wouldn&#39;t it be easier to find a line with a text string matching the word &quot;sendmail?&quot; Thankfully, we can use grep like this:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;rpm –qa | grep sendmail&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Which should give you:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[root@tower root]# rpm -qa | grep sendmail sendmail-8.13.1-3.RHEL4.5&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;[root@tower root]#&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Don&#39;t know if the string is capitalized or not? Just turn off the case-sensitive default:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;rpm –qa | grep –i sendmail&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Here&#39;s another example of how handy grep is. If we want some information on a process that is running on our server, we would run the command ps, which returns a fairly large list of running processes. To find the certain process that we&#39;re looking for, put the grep command after ps. Say I need to make sure my DHCP Server is running. I&#39;ll run the following:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ps ax | grep –i dhcp&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You should see something like the following:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;3058 ? Ss 0:00 /usr/sbin/dhcpd -cf /etc/dhcp/dhcpd.conf -q -pf /var/run/dhcp/dhcpd.pid -user dhcp -group dhcp&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
All set. Our DHCP server is running thanks to the simple and efficient grep.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Using sed&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The command sed (stream editor) is used to take a file, read a line, and change the line as specified by the command. This is another former UNIX utility available today in most Linux distributions.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s say we have a file called sedtest.txt, which contains the string &quot;1.0&quot;. We want to modify this file, changing the string to &quot;2.0&quot;. We can do this by doing the following:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;sed -e &#39;s/1.0/2.0/g&#39; sedtest.txt &amp;gt; sedtest2.txt mv –f sedtest2.txt sedtest.txt&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In this command line, s stands for substitute and g stands for global. Sedtest.txt is the input file (the one we&#39;re changing) and sedtest2.txt is the file we&#39;ve created from the changes of sedtest.txt. The second command takes the output file and renames it to the input file name (replacing the changes made)&lt;br /&gt;
&lt;br /&gt;
Besides substitution, there are other things sed is useful for. For example, the following deletes empty lines or lines that only contain spaces:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;sed -e &#39;/^ *$/d&#39; sedtest1.txt&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Notice how this one does not need an output file.&lt;br /&gt;
&lt;br /&gt;
Just like the Replace function in Word and Wordpad, sed is the Linux version of this handy tool.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/6602881591047351810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/using-grep-and-sed-to-find-and-replace.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6602881591047351810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/6602881591047351810'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/using-grep-and-sed-to-find-and-replace.html' title='Using grep and sed to find and replace'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2549337862784319946.post-5863198271219803222</id><published>2010-10-25T15:19:00.000-06:00</published><updated>2010-10-25T15:19:42.568-06:00</updated><title type='text'>Creating an inventory with nmap network scanning</title><content type='html'>Creating a system inventory is a common task for system and network administrators. Information security specialists often need inventories as well. Even in shops that have inventory tools, a method is often needed to validate the inventory and identify systems that the tool may not be aware of.&lt;br /&gt;
&lt;br /&gt;
The open source security audit tool nmap has all the necessary features needed to run ad-hoc or automated inventory processes. However, it is not obvious which parameters and output format are ideal to quickly create an inventory of your environment in a useable format.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Generating usable nmap results&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To create a usable inventory, the format of the generated data is crucial. If a report is being shared, a portable format is likely needed. Comma-separated values (CSV) are ideal, as this format can be loaded easily into spreadsheet and database programs. If the report is not shared, then a format that stands on its own must be included with the output. This article will provide example of the CSV generation.&lt;br /&gt;
&lt;br /&gt;
The inventory created by nmap and other network polling tools is a network-based inventory. The inventory created provides information that is critical to system, application and protocol management, such as a system&#39;s IP address, its operating system and the applications that it is running on network ports. The inventory will not include information such as how much memory the system has, how many processors there are, etc. This type of hardware inventory requires either an SNMP agent on the system or some other program or script running on the system to determine the hardware in the system.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Creating systems reports&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
A systems report can be quickly generated by nmap. Simply by scanning a network, an immediate list of systems and their protocols can be seen by using operating system identification (-O) and possibly verbose output (-v) against the complete network (/24):&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;nmap -O -v 192.168.1.0/24&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
However, the format is unruly, as pages and pages of output are generated. What is needed is a very clean output that can be easily loaded into a spreadsheet.&lt;br /&gt;
&lt;br /&gt;
Nmap supports the output parameter (-o) to influence how it should write data to standard out. By using it combined with G (-oG), nmap will create output that grep can work easily with, which makes our inventory creation much easier.&lt;br /&gt;
&lt;br /&gt;
Using operating system identification and the “grepable” output formatting, the following command can be used to run the raw reports and output the report to report.txt:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;nmap -O -oG report.txt 192.168.1.0/24&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This report, however, is still difficult to read and is not easily readable by a spreadsheet program or database, and includes the IP addresses that are not assigned to a system, since it scans the complete network:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;cat report.txt&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;# nmap 5.21 scan initiated Thu Sep 30 08:28:31 2010 as: nmap -O -oG report.txt 192.168.1.0/24&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Host: 192.168.1.0 () &amp;nbsp; &amp;nbsp;Status: Down&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Host: 192.168.1.3 () &amp;nbsp; &amp;nbsp;Status: Down&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Host: 192.168.1.4 () &amp;nbsp; &amp;nbsp;Status: Down&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Host: 192.168.1.5 () &amp;nbsp; &amp;nbsp;Status: Down&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Host: 192.168.1.1 (router.domain.com) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Status: Up&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Host: 192.168.1.1 (router.domain.com) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ports: 80/open/tcp//http///, 443/open/tcp//https///, 4567/open/tcp//unknown///, 8080/open/tcp//http-proxy///, 8443/open/tcp//https-alt/// &amp;nbsp; &amp;nbsp; &amp;nbsp;Ignored State:closed (995) &amp;nbsp; &amp;nbsp;OS: Linux 2.4.18 - 2.4.35 (likely embedded) Seq Index: 205 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IP ID Seq: All zeros&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;…&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To create a system report that includes IP address, hostname and operating system, we need to focus on the lines containing the information. The easiest way to identify these lines is to search for OS:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;grep &quot;OS:&quot; report.txt&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Host: 192.168.1.1 (router.domain.com) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ports: 80/open/tcp//http///, 443/open/tcp//https///, 4567/open/tcp//unknown///, 8080/open/tcp//http-proxy///, 8443/open/tcp//https-alt/// &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ignored State: closed (995) &amp;nbsp; &amp;nbsp;OS: Linux 2.4.18 - 2.4.35 (likely embedded) Seq Index: 205 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IP ID Seq: All zeros&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;…&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We now have the information necessary to create the report. However, a lot of information exists in the entry (such as open ports, sequences, etc.) that is not needed and should be dropped during the report generation. Let&#39;s remove Host:, Ports:, and all the ports included; OS:, everything starting with Seq up to the end of the line; and, finally, the first set of parenthesis around the host name:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;grep &quot;OS:&quot; report.txt | sed &#39;s/Host: //&#39; | sed &#39;s/Ports.*OS://&#39; | sed &#39;s/Seq.*$//&#39; | sed &#39;s/(//&#39; | sed &#39;s/)//&#39;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The ouput of this command is in this format:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;192.168.1.1 router.domain.com &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Linux 2.4.18 - 2.4.35 (likely embedded)&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now the IP address, hostname and operating system are easily identifiable, and it&#39;s a matter of piping that output to awk to add quotes and commas for the CSV. Basically, quotes are added around the IP address, the host name and all the words that make up the operating system identification tag:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;grep &quot;OS:&quot; report.txt | sed &#39;s/Host: //&#39; | sed &#39;s/Ports.*OS://&#39; | sed &#39;s/Seq.*$//&#39; | sed &#39;s/(//&#39; | sed &#39;s/)//&#39; | awk &#39;{print &quot;\&quot;&quot; $1 &quot;\&quot;,\&quot;&quot;$2&quot;\&quot;,&quot; $3 &quot; &quot; $4 &quot; &quot; &amp;nbsp;$5 &quot; &quot; &amp;nbsp;$6 &quot; &quot; &amp;nbsp;$7 &quot; &quot; &amp;nbsp;$8 &quot; &quot; &amp;nbsp;$9 &quot; &quot; $10 &quot; &quot; &amp;nbsp;$11 &quot; &quot; &amp;nbsp;$12 &quot; &quot; $13 &quot; &quot; $14 &quot;\&quot;&quot;}&#39; &amp;gt;report.csv&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the newly created report.csv file, the output is now in CSV format and can easily be loaded into a spreadsheet:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;cat report.csv&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&quot;192.168.1.1&quot;,&quot;router.domain.com&quot;,&quot;Linux 2.4.18 - 2.4.35 (likely embedded) &quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&quot;192.168.1.2&quot;,&quot;freddy&quot;,&quot;Linux 2.4.35&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&quot;192.168.1.6&quot;,&quot;computer.home&quot;,&quot;Linux 2.4.21 (embedded)|MontaVista embedded Linux 2.4.17 &quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&quot;192.168.1.7&quot;,&quot;IMAC.home&quot;,&quot;Apple Mac OS X 10.5 - 10.6.1 (Leopard - Snow Leopard) (Darwin&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&quot;192.168.1.8&quot;,&quot;new-host-3.home&quot;,&quot;Apple iPhone mobile phone (iPhone OS 3.0 - 3.2, Darwin 10.0.0d3) &quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&quot;192.168.1.11&quot;,&quot;new-host-5.home&quot;,&quot;Apple Mac OS X 10.5 - 10.6 (Leopard - Snow Leopard)&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&quot;192.168.1.15&quot;,&quot;AppleTV.home&quot;,&quot;Apple Mac OS X 10.4.8 - 10.4.11 (Tiger) (Darwin 8.8.0 – 8.11.1)&quot;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Conclusion&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Using the output of nmap, combined with the power of grep, sed, and awk, a complete network inventory can be generated in a matter of seconds on a small environment, and in a matter of minutes even in a very large environment.&lt;br /&gt;
&lt;br /&gt;
These same tools can be used by the information security specialist seeking to identify changes such as additions and removal of systems within the environment.</content><link rel='replies' type='application/atom+xml' href='http://amadys.blogspot.com/feeds/5863198271219803222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amadys.blogspot.com/2010/10/creating-inventory-with-nmap-network.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/5863198271219803222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2549337862784319946/posts/default/5863198271219803222'/><link rel='alternate' type='text/html' href='http://amadys.blogspot.com/2010/10/creating-inventory-with-nmap-network.html' title='Creating an inventory with nmap network scanning'/><author><name>Amadys Daniel</name><uri>http://www.blogger.com/profile/18051368450650950556</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>