2016年2月22日 星期一

Linux 常用指令

netstat 指令

netstat -pltu  或者是 -pltu

-p 通訊協定 : 顯示指連線的通訊協定.預設的狀況這個通訊協定包含 tcp, udp, tcpv6, or udpv6. 如果配合 -s 參數則是可以顯示統計數量

-t TCP

-u UDP

-a 顯示所有的連線


ps 指令
ps -A
-a 顯示同一終端下的所有程式

-A 顯示所有進程
a  顯示所有進程
c  顯示進程的真實名稱

error while loading shared libraries

error while loading shared libraries

錯誤訊息example

./openwsmand: error while loading shared libraries: libwsman_server.so.1: cannot open shared object file: No such file or directory

這篇的重點在兩個 1. 指令 ldconfig  2. lib 說明文件 /etc/ld.so.conf 和 /etc/ld.so.cache

1)如果共享庫文件安裝到了/lib或/usr/lib目錄下,那麼需執行一下ldconfig命令 
ldconfig命令的用途,主要是在預設搜尋目錄(/lib和/usr/lib)以及 etc/ld.so.conf內所列的目錄下,搜索出可共享的dynamic library(格式如lib*.so*),進而創建出動態裝入程序(ld.so)所需的連接和緩存文件.緩存文件默認為/etc/ld.so.cache,此文件保存已排好序的動態鏈接庫名字列表.

2)如果共享庫文件安裝到了/usr/local/lib(很多opensource的shared library都會安裝到該目錄下)或其它"非/lib或/usr/lib"目錄下,那麼在執行ldconfig命令前,還要把新shared library目錄加入到共享庫配置文件/etc/ld.so.conf中,如下:
cat /etc/ld.so.conf 
include ld.so.conf.d/*.conf 
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

3)如果shared library安裝到了其它"非/lib或/usr/lib"目錄下,但是又不想在/etc/ld.so.conf中加路徑(或者是沒有權限加路徑).那可以export一個Global變數 LD_LIBRARY_PATH ,然後運行程序的時候就會去這個目錄中找shared library.
LD_LIBRARY_PATH的意思是告诉loader在哪些目录中可以找到shared library. 可以設定多個搜索目錄, 這些目錄之間用冒號分隔開. 比如安装了一个mysql到/usr/local/mysql目錄下, 其中有一大堆shared library在/usr/local/mysql/lib下面, 則可以在.bashrc或.bash_profile或shell里加入以下:

export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH

一般來講這只是一種臨時的解決方案,在沒有權限或臨時需要的時候使用

4)如果程序需要的庫文件比系統目前存在的村文件版本低,可以做一個鏈接比如:
error while loading shared libraries: libncurses.so.4: cannot open shared object file: No such file or directory 
ls /usr/lib/libncu*
/usr/lib/libncurses.a   /usr/lib/libncurses.so.5
/usr/lib/libncurses.so  /usr/lib/libncurses.so.5.3

可见虽然没有libncurses.so.4,但有libncurses.so.5,是可以向下兼容的
建一个链接就好了
ln -s  /usr/lib/libncurses.so.5.3  /usr/lib/libncurses.so.4

ref: http://blog.chinaunix.net/uid-26212859-id-3256667.html

Digest Authentication

Digest Authentication Concept

將password hash之後再送出去


HTTP Digest Authentication

example :
客戶端請求 (無認證)
GET /dir/index.html HTTP/1.0
Host: localhost
失敗 , 
伺服器響應
HTTP/1.0 401 Unauthorized
Server: HTTPd/0.9
Date: Sun, 10 Apr 2005 20:26:47 GMT
WWW-Authenticate: Digest realm="testrealm@host.com",
                        qop="auth,auth-int",
                        nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
                        opaque="5ccc069c403ebaf9f0171e9517f40e41"
Content-Type: text/html
Content-Length: 311

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML>
  <HEAD>
    <TITLE>Error</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
  </HEAD>
  <BODY><H1>401 Unauthorized.</H1></BODY>
</HTML>
客戶端請求 (用戶名 "Mufasa", 密碼 "Circle Of Life")
GET /dir/index.html HTTP/1.0
Host: localhost
Authorization: Digest username="Mufasa",
                     realm="testrealm@host.com",
                     nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
                     uri="/dir/index.html",
                     qop=auth,
                     nc=00000001,
                     cnonce="0a4f113b",
                     response="6629fae49393a05397450978507c4ef1",
                     opaque="5ccc069c403ebaf9f0171e9517f40e41"


Client  random產生cnonce
然後利用 (password + cnonce + nonce + nc + 其他) 產生hash value: “response” ,
然後把這些值都夾在Http header中送給Server
這些統稱為 Authorization credentials


接下來的通訊

如果Web Browser  ,  接下來每個 Http Get都會夾帶 Credentials .
但是 cnonce and nc都不同  , 所以response也都不同


Example in RFC 2617

HA1 = MD5( "Mufasa:testrealm@host.com:Circle Of Life" )
= 939e7578ed9e3c518a452acee763bce9 HA2 = MD5( "GET:/dir/index.html" )
= 39aff3a2bab6126f332b942af96d3366 Response = MD5( "939e7578ed9e3c518a452acee763bce9:\
dcd98b7102dd2f0e8b11d0f600bfb0c093:\
00000001:0a4f113b:auth:\
39aff3a2bab6126f332b942af96d3366" )
= 6629fae49393a05397450978507c4ef1

HA1 = MD5 ( USERNAME:realm:PASSWORD )
HA2 = MD5(method:digestURI
response = MD5(HA1:nonce:nc:cnonce:qop:HA2)

在 Linux中有簡易驗證MD5的方式 

$echo -n Administrator:OPENWSMAN:Realtek | md5sum
下面是得到的結果
7b33ee9e26499e7ecc6c3737d8ae5cec  -



Apache 提供的 utilities :  htpasswd and htdigest 

htdigest -C <filename> <realm> <Accoumt>
$ htdigest -c Administrator_digest.passwd OPENWSMAN Administrator

(## The realm for openwsman has to be OPENWSMAN ##)

Linux 安裝 sshd 和 samba

安裝 OpenSSH Server 

1. sudo apt-get install openssh-server
2. /etc/ssh/sshd_config  應該不需要修改
3.  sudo /etc/init.d/ssh restart


[samba] 使用user 登入的簡易設定


1. sudo apt-get install samba

2. 修改 /etc/samba/smb.conf

       [share1]
        comment = share
        path    =       /share
        browseable = yes
        writable=       yes
        public  =       yes


3.設定使用者密碼 , 再檢查/etc/samba/smbpasswd 是否有新增使用者

    smbpasswd -a test1 
    cat /etc/samba/smbpasswd



在Linux上安裝套件1

在Linux上要安裝一個套件,最重要的是要去看README、INSTALL等說明文件
因為它會告訴你,怎麼做才會安裝成功。


通常安装一個套件的步驟是:(以gtk為例)
tar jxvf gtk+-2.4.13.tar.bz2 (解開套件)
cd gtk+-2.4.13/ (進入解開套件的目錄下)
執行./configure 
PS:似乎在某些環境下./configure會造成terminal退出
可以試試看.configure (目前是沒有遇到這種情形啦@@)

若configure成功後,則會建立Makefile
再來執行make

PS:若configure沒有成功,此時執行make,則會出現以下的訊息
"make: *** No targets specified and no makefile found. Stop."

make成功後
執行make install 則會開始安裝了。
--------------------------------------------------------------------
(小結)安裝套件的步驟
(1) 先去看一看README、INSALL(雖然英文不夠好...但總有一天你會開竅的)
(2) ./configure
(3) make clean (為什麼多了這個步驟...因為以前可能有編譯失敗過)
(所以為了以防萬一...clean掉一些*.o等東西)
(4) make
(5) make install


from  http://note1.pixnet.net/blog/post/9991912-在linux上安裝套件

2016年2月21日 星期日

在Linux上安裝套件2

如何檢查Linux版本

Kernel 

$ uname -r

檢查Linux distribution version

$ cat /proc/version
or
$ cat /etc/issue



Debian / Ubuntu 安裝套件

dpkg是Debian底層的套件管理程式,其上還有強大的apt,在其上更有非常強大的aptitude管理系統


sudo apt-get update更新套件清單。
sudo apt-get upgrade升級系統已安裝套件的版本,此指令可一次升級所有已安裝套件的版本,也可以單獨升級某指定套件。
sudo apt-get dist-upgrade  <name>升級系統已安裝套件的版本,一併升級具相依性套件的版本。
sudo apt-get install  <name>安裝套件。
sudo apt-get remove  <name>移除套件,但保留該套件設定檔。
sudo apt-get autoremove  <name>移除套件,並且移除與該套件具有相依性之套件。
sudo apt-get --purge remove  <name>移除套件,一併移除該套件設定檔。
sudo apt-get clean移除套件的安裝原始檔。
sudo apt-get autoclean移除已經無法再下載的套件安裝原始檔。
sudo apt-get check檢查套件是否有相依性的問題。
apt-cache search  <name>透過此指令,我們可以使用關鍵字來搜尋套件完整名稱,name 為某套件的查詢關鍵字。
apt-cache showpkg  <name>查詢某套件的所有資訊。
apt-cache pkgnames  <name>查詢系統中所有可用的套件名稱。
apt-cache depends  <name>查詢與某套件有依存關係的所有套件,並顯示是否有衝突套件及建議取代套件

apt-get -s install              You can run a simulation to see what would happen if you                                                                  upgrade/install a package:           

apt-get -V -s upgrade       To see all possible upgrades, run a upgrade in verbose mode and (to                                              be safe) with simulation, press n to cancel:

apt-cache policy <pkg>     The option policy can show the installed and the remote version                                                     (install candidate) of a package

apt-show-versions <pkg>   If installed, shows version information about one or more packages

查詢已安裝的套件
dpkg -l 



aptitude

aptitude 是比apt-get更強大的安裝工具 , 使用方式類似
aptitude install <package>
Passing -V will show detailed information about versions, again to be safe with the simulation switch


aptitude -V -s install <package>
Displays the versions of specified packages.


aptitude versions <package>

更新apt Host

有時候某些套件找不到 , 可能要修改/etc/apt/sources.list 中的 host列表 , 並且更新apt
example : 
   1. 在您的 /etc/apt/sources.list 文件中像下面這樣添加一行:
          deb http://ftp.de.debian.org/debian sid main  
   2.執行 $apt-get update 



下載 原始檔進行安裝

一般下載一個xxx.tar.baz解開後都會提供一個.configure和install
以進行下列方式的安裝


# ./configure
# make
# make install


下載 RPM檔進行安裝

# rpm -ivh  MySQL-client-3.23.57-1.i386.rpm