2010-12-28

[SSH] 以 key authentication 連 remote host

SSH


平常用 ssh 登入主機時,都是以打密碼的方式進行驗證
還有另一個驗證的方法,就是用 public key 跟 private key 來驗證

ssh-keygen 可以產生的 key 有三種
rsa1, rsa2, dsa
這邊以 rsa2 為例

ssh-keygen

openSSH 本身就有包含 ssh-keygen 這個產生 key 的工具
$ ssh-keygen -t rsa

ssh-keygen 會跑出以下訊息:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/nyo/.ssh/id_rsa):
# 設定存放 key 的位置,按 enter 使用預設值
Enter passphrase (empty for no passphrase):
# 輸入 passpharse,想要不打密碼就登入的話,就讓它空白;或是打上 passpharse 之後再交由 ssh-agent 或任何 key 管理系統保管
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
XX:XX:18:XX:19:XX:XX:XX:XX:XX:13:XX:XX:05:XX:XX user@Ubuntu


現在在 ~/.ssh/ 裡我們有一把 public key (id_rsa.pub) 跟一把 private key (id_rsa)
只要把這兩隻 key 保管好,把 public key 放到你要連線的主機就可以了!

把 public key 放到你要連線的主機
$ scp ~/.ssh/id_rsa.pub username@server:~/
連到該主機上,這時你還是只能用打密碼的方式登入
$ ssh username@server
將 public key 加到系統預設放 public key 的地方:authorized_keys
$ cat id_rsa.pub >> ~/.ssh/authorized_keys

設定完成,你再次登入該主機就是以 key authentication
如果你沒打 passphrase 就可以直接登入
有打 passphrase 就打 passphrase

之後如果還要連到其他的主機,只要再將原本的 public key 送到該主機的 authorized_keys 就可以了

SSH 免密碼登入 - JosephJ
ssh keygen 免輸入密碼 - Tsung

2010-12-27

[BH] 文章更新時間

blogger 內建只會顯示文章的“發表時間”,卻沒有“更新時間”這個項目
為了做一些區別,“更新時間”這個東西似乎是有必要的
這樣對原本文章做修改才會有所記錄

在網路上找到 abin 大的文章,可以幫自己的文章加上更新時間

將以下 script 加到 <head></head> 裡面
<script type="text/javascript">
//<![CDATA[
<!-- Function used for generating the last update time for each post: showPostUpdateTime() -->
function showPostUpdateTime(json) {
  var updateTime = json.entry.updated.$t;
  var publishTime = json.entry.published.$t;
  if (updateTime.substr(0,10) != publishTime.substr(0,10))
    document.write(' | Updated at '+updateTime.substr(0,10)+' '+updateTime.substr(11,5));
}
//]]>
</script>


再將以下紅色的部份加到對應的位子就可以了
<span class='post-timestamp'>
  <b:if cond='data:top.showTimestamp'>
    <data:top.timestampLabel/>
    <b:if cond='data:post.url'>
      <a class='timestamp-link' expr:href='data:post.url' title='permanent link'><data:post.timestamp/></a>
      <!-- Fixed for display post update time -->
      <b:if cond='data:blog.pageType == "item"'>
        <script expr:src='"/feeds/posts/default/" + data:post.id + "?alt=json-in-script&callback=showPostUpdateTime"' type='text/javascript'/>
      </b:if>
    </b:if>
  </b:if>
</span>

我有做一些自己的修改
詳細的介紹就到 abin 大的網誌看吧

增加文章更新時間 (Show Post Update Time) by abin

2010-12-22

[Vim] 最近的 vimrc 設定內容

這是目前所使用的 .vimrc 設定
用 gvim 的 "轉換成 html 格式" 漂亮的展示一下
設定的說明也一起寫在 vimrc 裡了



 1 " 打開語法效果
 2 syntax on
 3 " 按下 tab 後會輸入的空白數目
 4 set softtabstop=4
 5 " 以空白當tab
 6 set expandtab
 7 " 縮排為四個空白
 8 set shiftwidth=4
 9 " 顯示當前模式
10 set showmode
11 " 顯示游標所在行列
12 set cursorline
13 set cursorcolumn
14
15 " 在狀態列顯示游標所在行列狀態
16 set ruler
17 " 顯示行號
18 set number
19 " hightlight search
20 set hls
21 " 尋找不分大小寫
22 set ignorecase
23 " 搜尋時,自動跳到符合的字串
24 set incsearch
25 " 自動縮排
26 set ai
27 " 色彩主題 torte
28 colorscheme torte 
29
30 " 游標形狀跟閃爍速度
31 set guicursor+=n-v-c:block-cursor-blinkwait300-blinkon90-blinkoff90
32 set guicursor+=i:ver3-cursor-blinkwait200-blinkon110-blinkoff110
33 set guicursor+=v:ver90-cursor-blinkwait200-blinkon150-blinkoff150
34
35 " statusline
36 set ls=2
37 set statusline=%<%f\ %m%=\ %h%r\ %-19(\ [ASCII:%b]\ [%p%%]\ %3l,%02c%03V%)%y
38 highlight StatusLine term=bold,reverse cterm=bold,reverse

2010-12-20

[Git] 幫程式碼寫日記 - Git

Git logo

Linus:
"I'm an egotistical bastard, and I name all my projects after myself. First Linux, now git."

git 是一套分散式版本控制系統,由Junio Hamano 和 Linus Torvalds 開發,一開始是要用來取代非開源的 BitKeeper 分散式版本控制系統。
目前有非常多的專案都是用 git 在開發:
Git, Linux kernel, perl, Gnome, Ruby on Rails, Andruid, Facebook, jQuery......

我也是 Git 的新手,所以要我介紹 Git,不如看專家介紹來的實在!

關於 Git 神奇的地方:
我愛Git - Jserv: jserv.sayya.org/writing/loving-git.pdf
Why Git is Better Than X
Why Git is Better Than X(繁體中文)
Git @ wiki
gittutorial(7)
Git 版本控制系統 (1) - ihower


一些不錯的 Git 網站:
Pro Git - Pro Git Book
git ready
Git Magic - Preface

2010-12-16

[BH] 文章自動收合:繼續閱讀懶人加強版

現在的 blogger 己經有內建的 read more 功能
是可以自行在文章中加到想要的位子,算是很方便的功能

不過當你是要讓所有的文章都自動加上 read more 的時候
加個外掛也是可以做到的

目前使用的是:
繼續閱讀懶人加強版 CJH

作者對安裝方法跟如何設定都有清楚的說明


加上 div class read-more-controller 的 CSS style
div.read-more-controller {
  background: #222;
  font-size: 1.5em;
  text-align: center;
  border-bottom: 2px solid #444;
  border-right: 2px solid #444;
  border-top-left-radius: 1em 1em;
  border-top-right-radius: 1em 1em;
}

2010-12-15

[BH] terminal 跟 subtitle 的 CSS style

弄了兩個 css style 分別是給 terminal 跟 subtitle
區別一下,不要都用 blockquote...

pre.termCommand {
font-family: monospace;
color: #DD2;
background: #222;
padding: 0.3em 0.5em;
margin: 0.2em 0.5em;
border: 1px solid silver;
}


h3.sub-title {
color: $(post.title.text.color);
margin:0.5em 0 0 0;
line-height: 1.2;
border-bottom: 2px solid silver;
}

2010-12-07

[BH] blockquote tag 跟 reference 的 CSS style

設計一下 blockquote 看起來更醒目


blockquote {
color:#222;
background-color: #FFEBCD;
padding: .3em .5em;
border: 2px #DB9 dashed;
}


reference {
display: block; /* fixes a strange ie margin bug */
background: #FEE url(http://chenkaie.googlepages.com/Code_REF.gif) left top repeat-y;
border: 1px dotted #933;
padding: 10px 10px 10px 20px;
margin: 5px 0 0 5px;
font-size: 13px;
font: Courier New;
line-height: 1.6em;
}



參考網路上他人的設計
之後再做調整!

似乎可以用 blogger 裡的變數去設定CSS

[CSS] A Cool blockquote for "Code style" and some blogging tips

[Git] 一些基本的環境設定 (2010/12/15 Update!)

使用 git 第一步是設定你的基本資料,也就是 user name 跟 user email

$ git config --global user.name "username"
$ git config --global user.email "username@email.com"

設定顯示顏色
$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto
$ git config --global color.log auto

設定會存在 ~/.gitconfig
或者可以下指令看
$ git config -l

自訂 log 格式到 lg,當然你也可以定義其他 alias
$ git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"


讓 Git 忽略特定檔案


使用者自行建立名為 .gitignore 的檔案
ex.
# 註解,會被忽略。
*.a       # 不要追蹤檔名為 .a 結尾的檔案
!lib.a    # 但是要追蹤 lib.a,即使上方已指定忽略所有的 .a 檔案
*.swp
*~

或是,只想要忽略當前的 repository 中的檔案
將檔案設定加到 .git/info/exclude 中就可以了

[Git] Start To Git

以 ubuntu 來說,要裝 Git
$ sudo apt-get install git-core
這樣就裝好了..結束!了嗎?

# 為專案新增 Git Repositiory


假設專案的資料夾為 project
$ cd project
$ git init

git 會 reply
Initialized empty Git repository in .git/
所有 repository 所需要的資料通通會在 project/.git/ 裡面

接著將 project 裡要讓 git 追蹤的檔案加入
$ git add .
(. 指目前所在目錄,當然也可以指定檔案)

git 會把 add 的檔案暫存起來

最後輸入 commit 指令,把資料 commit
$ git commit
輸入指令後會進入編輯器,為目前的資料變動加上說明
存檔後此次 commit 的資料就會加入 repository 中


官方網站跟手冊:
Git - the fast version control system
official Git tutorial : a good place to get started.
Everyday GIT : in 20 commands is good for a useful minimum set of commands.
Git User Manual

2010-12-01

[PHP] The DateTime Class

Doctrine 2 裡記錄時間都是用 PHP 的 DateTime Class
所以小研究一下

In PHP 5.2+

新增一個當前時間的 DateTime Class
$date = new DateTime("now");
ps. string "now" 可以不用打,預設就是 "now"

跟據 format 回傳 DateTime Class 的時間
echo $date->format('Y-m-d H:i:s');

參考資料:
http://www.php.net/manual/en/class.datetime.php