pam_unix禁用密码强度检查

/etc/pam.d/common-password

man pam_unix

minlen=n
      Set a minimum password length of n characters. The default value is
      6. The maximum for DES crypt-based passwords is 8 characters.

  obscure
      Enable some extra checks on password strength. These checks are
      based on the "obscure" checks in the original shadow package. The
      behavior is similar to the pam_cracklib module, but for
      non-dictionary-based checks.

改成如下:
password [success=1 default=ignore] pam_unix.so minlen=1 sha512
可禁用密码强度检查

pkg-config

To add a new lib to pkg-config environment:

1. fabricate a .pc file:

libme.pc
prefix=/home/y/.programs/libme
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
bindir=${exec_prefix}/bin

Name: libme
Description: misc execution Library
Version: 1.0.0
Libs: -L${libdir} -lme
Libs.private:flags: -I${includedir}

system examples in
/usr/lib/pkgconfig
/usr/share/pkgconfig/

2. set PKG_CONFIG_PATH

export PKG_CONFIG_PATH=xxx

3. test

pkg-config –cflags –libs libme

email notification tools

1. xdg-email : xfce默认email client

fakeCmd = “xdg-email \
–attach xx \
–subject ‘subj’ \
–body ‘Attached you find the logo for the contest.’ \
'xx@live.com

2. 直接呼叫开源版雷鸟icedove

theCmd = ‘icedove -compose “to=xx@gmail.com,subject=%s,attachment=file:///home/y/temp/zip/%s,body=%s”‘ % (
filename,
filename,
filename
)

3. 使用原始的/usr/bin/mail

echo "Sending Test Email" | mail -s "Hello" testing@test.com

mail -s "`date`" xx@yy.com < /etc/hosts

4. java

javax.mail:mail:1.4.1

5. mailx

mailx -s "subject:test mail" foo@bar.com
mailx -s "subject:test mail" foo@bar.com

6. sendmail

sendmail foo@bar.com < /etc/hosts

———————————————–

gerrit email设置(使用aliyun个人邮箱)

[sendemail]
    smtpServer = smtp.aliyun.com
    smtpServerPort = 465
    smtpEncryption = SSL
    smtpUser = XX@aliyun.com
[user]
    email = XX@aliyun.com

使用默认sendmail:

/usr/bin/mail -> /etc/alternatives/mail -> /usr/bin/bsd-mailx
/usr/bin/mailx -> /etc/alternatives/mailx -> /usr/bin/bsd-mailx

使用heirloom-mailx

/usr/bin/mail -> /etc/alternatives/mail -> /usr/bin/heirloom-mailx
/usr/bin/mailx -> /etc/alternatives/mailx ->/usr/bin/heirloom-mailx

配置文件在: /etc/nail.rc

set from=XX@aliyun.com
set smtp=smtps://smtp.aliyun.com:465
set smtp-auth=login
set smtp-auth-user=XX@aliyun.com
set smtp-auth-password=???
set auth-login=XX

安装以及配置

参考https://holarails.wordpress.com/2013/11/17/configure-sendmail-in-ubuntu-12-04-and-make-it-fast/

apt-get install sendmail
sendmailconfig

git - distributed version control

Git常用操作命令收集:

Administration:
git init

Starting …
git clone –progress -v git://github.com/jquery/jquery.git jquery
git fetch -a
git fetch –tags

Configuration: .gitconfig
git config –global user.name “xx”
git config –global user.email “xx@xx.com
git config –global alias.co checkout
git config –global alias.b branch
git config –global alias.br branch -r
git config –global alias.ci commit
git config –global alias.st status
git config –global alias.unstage ‘reset HEAD –’
git config –global alias.last ‘log -1 HEAD’
git config –global core.autocrlf false
git config –global alias.logs ‘log –color –graph –decorate=short –all –date-order’
git config –global core.ignorecase false
git config –global mergetool.fugitive.cmd ‘gvim -f -c “Gdiff” “$MERGED”‘
git config –global merge.tool fugitive

单个project的git配置位于.git/config
可以用如下命令搞定:
git config user.name “xx”
git config user.email “xx@xx.com

Configuration: .gitignore
.gitignore
target
bin
.db .[oa]
*~
!lib.a
/TODO

Git Insight:
Log:
git log –graph –decorate –branches
git log –graph –decorate –all
git log -[n]
git log –pretty=format:”%h - %an, %ar : %s”

Remote
查看远程仓库:$ git remote -v
添加远程仓库:$ git remote add [name] [url]
删除远程仓库:$ git remote rm [name]

拉取远程仓库:$ git pull [remoteName] [localBranchName]
推送远程仓库:$ git push [remoteName] [localBranchName]
查看远程branch: git branch -r
把远程分支check到本地: git checkout -b alpha origin/alpha
check出远程的一个tag: git checkout -b alpha1.1.1 1.1.1.20110501_alpha

Branch:
查看本地分支:$ git branch
查看远程分支:$ git branch -r
创建本地分支:$ git branch [name] –> 切换分支:$ git checkout [name]
创建新分支并立即切换到新分支:$ git checkout –track -b [name]
删除分支:$ git branch -d/-D [name]

Merge:
git merge –no-commit –no-ff [name] 执行merge,但是不做本地修改
git merge [name]

Push:
本地分支push到远程 $ git push origin [name]
本地版本push到远程 $ git push origin [name],
$ git push origin refs/tags/tagname

删除远程版本: $ git push origin :refs/tags/[name]
$ git push origin :[name]
删除远程分支: $ git push origin :heads/[name]
$ git push origin :[name]

Tag:
查看版本:$ git tag
创建版本:$ git tag [name]
创建annoted tag:git tag -a v1.2 -m “This is tag v1.2”
删除版本:$ git tag -d [name]

Cherry-pick:
The advantage is commit log will be linear and clean

git clean -xdf

git mergetool
–>manually edit, save

Best Work flow practiSe:
clone the remote repo
git checkout -b my_new_feature
..work and commit some stuff
git rebase master
..work and commit some stuff
git rebase master
..finish the feature
git checkout master
git merge –squash my_new_feature
git branch -D my_new_feature
In fact, our workflow is a little different, as we tend to do squash merges instead of raw merges. This allows us to turn our entire feature branch into a single commit on master. Then we delete our feature branch. This allows us to logically structure our commits on master, even if they’re a little messy on our branches.

git-bisect - Find by binary search the change that introduced a bug

git rebase []

: git checkout , then …
git log ..HEAD > temp
git reset –hard
git reset –hard , with –onto

“git reset” means “git reset –mixed”

git rebase master
git rebase master topic = git checkout topic, git rebase master
git rebase –onto master E topic

git gc –auto一般不做事,除非have around 7,000 loose objects or more than 50 packfiles
git gc –aggressive –prune 可以清理,
git count-objects -v 查看有多少object
git fsck –strict 检查git

git blame 查看谁在那个commit改了什么内容
git blame -L 23,44
git blame -L 23,+10

HOW TO USE SUBMODULE

添加submodule
git submodule add git://github.com/chneukirchen/rack.git rack
git commit -m ‘first commit with submodule rack’
获取submodule
git submodule init 如果找不到iconv2,需要手动复制过去
git submodule update
更新submodule:
进入子目录进行更新
在git中更新submodule:
进入submodule, git merge origin/master
git submodule update

git clone …
git submodule update –init –recursive

清理垃圾:
git gc –prune=now
git gc –prune= defaults to prune objects older than two weeks ago.

让git区分大小写
git config –global core.ignorecase false
强制修改文件大小写
git mv -f name.java Name.java

HOW TO EDIT LAST COMMIT:

Suppose you just made a commit, and you’re working on some more changes, when you realize you made a mistake in the previous commit. Here’s how you can go back and fix it, without losing any of the new work you’ve done since you commited:

1.Save your work so far.
2.Stash your changes away for now: git stash
3.Now your working copy is clean at the state of your last commit.
4.Make the fixes. (If you just want to change the log, skip this step.)
5.Commit the changes in “amend” mode: git commit –all –amend
6.Your editor will come up asking for a log message (by default, the old log message). Save and quit the editor when you’re happy with it.
7.The new changes are added on to the old commit. See for yourself with git log and git diff HEAD^
8.Re-apply your stashed changes: git stash apply
9.Continue happily with your life.

HOW TO EDIT HISTORY COMMIT: we rewrite the history

1.Save and stash your work so far.
2.copy the commit you want to edit onto your clipboard.
3.Start the interactive rebase process, git rebase –interactive ID^, with the ^ to refer to the parent of that commit
3.Your editor will come up with several lines like pick d3adb33 Commit message, one line for each commit since the older one.
4.Change the word “pick” to “edit” in front of the commit you want to change.
5.Save and quit.
6.Edit your project files to make the correction, then run git commit –all –amend.
7.After you’ve committed the fixed version, do git rebase –continue.
8.Git will do its magic, recreating all the commits since then.
You might need to resolve some conflicts, if the change you made affected later commits. Follow Git’s instructions to resolve those.
9.Once the rebase is done, re-apply the stash and continue happily with your life.

echo ‘.zip -delta’ > .gitattributes
echo ‘
.tar -delta’ > .gitattributes
echo ‘.bz2 -delta’ > .gitattributes
echo ‘
.tar -delta’ > .gitattributes
echo ‘.a -delta’ > .gitattributes
echo ‘
.so -delta’ > .gitattributes
echo ‘.gz -delta’ > .gitattributes
echo ‘
.bmp -delta’ > .gitattributes
echo ‘.jpg -delta’ > .gitattributes
echo ‘
.png -delta’ > .gitattributes
echo ‘*.zip -delta’ > .gitattributes

web浏览git代码:
git instaweb
只能浏览代码

gitweb

git reset –soft HEAD^^
回到前两个commit,然后修改,commit可以悔2步棋

搭建git://服务器:
(0)准备git
/home/yu/t/code.git是一个真正的bare git
(1)apt-get install git-daemon-run
(2)修改/etc/sv/git-daemon/run
注意base-path名字后面不能加/,否则出错,git-daemon很蠢
加入–syslog就可以查看详细log,便于debug
加入–export-all可以不用给每个git都加入whitelist
git-daemon –verbose –syslog –reuseaddr –export-all –base-path=/home/yu/t /home/yu/t/code.git
(3)运行
sv down git-daemon
sv up git-daemon
(4)测试
git clone git://IP/code

查看2个commit之间的ancestor关系:
git merge-base –is-ancestor
查看n个commit的所有merge-base(best common ancestor):可能不止一个(criss-cross merges)
git merge-base -a –octopus
merge-base(best common ancestor):可能不止一个(criss-cross merges like this:

---1---o---A
    \ /
     X
    / \
---2---o---o---B

Performance

测试速度
time git status
查看调用了多少次lstat
strace git status 2>&1 1>/dev/null | grep lstat | wc -l
清除disk cash
sudo sh -c “sync; echo 3 > /proc/sys/vm/drop_caches”
sudo sh -c “sync; echo 0 > /proc/sys/vm/drop_caches”

track HTTP requests:
GIT_CURL_VERBOSE=1. GIT_TRACE_PACKET=1

查看所有包含refs/for的refs:
git for-each-ref refs/for

删除所有refs/for的refs:
for n in $(git for-each-ref –format=’%(refname)’ refs/for);
do
git update-ref -d $n;
done

patch

(1)create: git format-patch 3553e4ca0cf2cd..cbd9946fd591f8 –cover-letter –output-directory out
(2)apply : git apply xx.patch
(3)revert: patch -p1 -R < xxx/1.diff

(1)create: git diff xx yy > 1.diff
(2)apply : patch -p1 < 1.diff
(3)revert: git apply -R xxx/1.diff

重写commit的email
git commit –amend –reset-author

cherry-pick range:
git cherry-pick A..B
but it’s not the best, git rebase -i has better sequencing control

清理git历史
bfg repo cleaner
git filter-branch

GPG usage

1. Documents

http://www.ruanyifeng.com/blog/2013/07/gpg.html
http://wiki.ubuntu.org.cn/GPG/PGP
使用subkey
https://wiki.debian.org/Subkeys
相关post:
Android ROM用的key
http://cfig.github.io/2015/10/15/signing-keys-in-android/

2. GUI tools

http://gnupg.archive.sunet.se/related\_software/frontends.html
‘seahorse’ for GNOME is sufficient.

3. 命令行工具

3.1 密钥管理

生成密钥

gpg --gen-key

Tips: To use a shorter name(uid) which is less than 5 characters, need to add --allow-freeform-uid to the command line.

添加签名用的subkey

gpg --edit-key <keyid>
> addkey
> (4) RSA (sign only)

Tips: 同样办法可以添加用于加密的subkey

添加不同email的uid

gpg --edit-key <keyid>
> adduid
Real Name: <name>
Email address: <email>
Comment: <comment or Return to none>
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
Enter passphrase: <password>
gpg> uid <uid>
gpg> trust
Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y
> save

删除key

gpg --delete-keys

查看公钥

gpg -K
gpg -k

查看私钥

gpg --list-keys

导出公钥

gpg --armor --export <uid>
gpg --armor --export <name>@gmail.com

导入公钥

gpg --import <pub.key>

导出私钥

gpg --armor --export-secret-keys <uid>
gpg --armor --export-secret-keys <name>@gmail.com

仅导出subkey私钥

gpg --export-secret-subkeys

导入私钥

gpg --allow-secret-key-import --import <private.key>
gpg --fingerprint

信任公钥

gpg --edit-key <uid>
gpg > trust
gpg > 5

上传公钥

gpg --keyserver hkp://pgp.mit.edu --send-keys 72355772

下载公钥

gpg --keyserver pgp.mit.edu --recv-key 72355772

召回公钥

gpg --gen-revoke FD9D429D
gpg --import revoke.2016.pubkey.txt
gpg --keyserver pgp.mit.edu --send-keys  FD9D429D

Tips: 把--gen-revoke的结果存入文件,然后导入,最好把导入的key上传

3.2 密钥使用

加密文件

gpg -e -r <name>@gmail.com <file>

解密文件

gpg -d <file.gpg>

加密解密

gpg --recipient <name>@gmail.com --output <file.en> --encrypt <file>
gpg --output <file.dec> --decrypt <file.en>
gpg <file.en>

签名

gpg --sign <file>
gpg --clearsign <file>
gpg --detach-sign <file>
gpg --armor --detach-sign <file>

验证签名

gpg --verify <file.asc> <file>

签名并加密

gpg --local-user <name>@gmail.com --recipient <name>@gmail.com --armor --sign --encrypt aa.py

4. misc

可以export GNUPGHOME临时改变GPGHOME目录

如果碰到下面问题

gpg: signing failed: Inappropriate ioctl for device
可以这样解决
export GPG_TTY=$(tty)

如果在gpg2上碰到导入问题, 可以尝试杀掉gpg agent,

compile new debian kernel

document

www.debian.org/releases/stable/i386/ch08s06.html.en

1. install pkgs

apt-get install kernel-package fakeroot linux-source pkg-config libncurses5-dev libqt4-dev

2. download kernel source

Assuming /usr/src/linux-source-3.16.tar.xz is the source code.

3. make

copy current kernel config from /boot/config-*

make menuconfig/xconfig

make-kpkg clean

fakeroot make-kpkg –initrd –revision=1.0custom kernel_image

4. install

dpkg -i ../linux-image-xxx.deb

wpa supplicant

wifi:
The most commonly used tools are wireless-tools & wpa_supplicant. wpa_supplicant serves as daemon, wpa_cli serves as client.

1. wpa_supplicant.conf

update_config=1
ctrl_interface=socket_dir
eapol_version=1
ap_scan=1
fast_reauth=1

2. start daemon

wpa_supplicant -Dnl80211 -iwlan0 -c wpa_supplicant.conf -d
  -D: driver
  -d: debug
  -c: config file

3. run client

wpa_cli -i wlan0 -p socket_dir/
  >scan
  >scan_results
  >add_network
  >set_network 0 ssid "NTGR-2.4G"

  ---WPA-PSK/WPA2-PSK
  >set_network 0 psk ""
  ---OPEN
  >set_network 0 key_mgmt NONE
  ---WEP
  >set_network 0 key_mgmt NONE
  >set_network 0 wep_key0 "the_pwd"

  >select_network 0
  >enable_network 0
  >list_networks
  >status
  >save_config
  >quit

4. get IP

dhclient wlan0

5. do anything u want

6. stop wpa_supplicant in wpa_cli

>terminate

7. final wpa_supplicant.conf

ctrl_interface=socket_dir
update_config=1

network={
     ssid="NTGR-2.4G"
     psk="12345678"
}

Microdia keyboard driver

0.现象

使用Fujitsu KH800键盘,linux下组合键打不出来

1. 用户空间查看keycode的工具:

console:
evtest
showkey

GUI:
xev

初步结论:
查看下来linux把Shift_L,Shift_R,Ctrl_L, Ctrl_R都映射成了Shift_L。keycode看也不能区分。应该是kernel对硬件的键值识别有问题。

2. 查看硬件信息和driver:

lsusb:
Bus 002 Device 006: ID 0c45:7603 Microdia

/dev/input/by-id/
lrwxrwxrwx 1 root root 9 2015-09-09 10:24 usb-SONiX_USB_Keyboard-event-kbd -> ../event1
lrwxrwxrwx 1 root root 9 2015-09-09 10:24 usb-SONiX_USB_Keyboard-if01-event-kbd -> ../event3

3. 寻找Microdia driver解决方案

讨论帖
http://askubuntu.com/questions/572394/ctrl-and-alt-keys-mapped-to-shift-for-some-reason

解决方法
”Linux Microdia Keyboard Chipset Driver“
https://bitbucket.org/Swoogan/aziokbd
此driver是写给Azio L70的,但是也能用。

4. 解决方案修改

不用DKMS,直接安装ko,启动后需要重新插拔键盘,再执行如下脚本
echo ‘## Starting fuji module ##’
modprobe aziokbd
echo ‘## Attempting to reload fuji usbhid module ##’
rmmod usbhid && modprobe usbhid quirks=$quirk

可以把脚本fuji放到/etc/init.d/中,补充do_start(), do_stop()脚本,然后:
update-rc.d fuji defaults。系统启动就可以自动执行脚本。

5 Appendix

5.1: Source code

aziokbd fork on github

5.2: /etc/init.d/fuji

https://github.com/cfig/utils/blob/master/aziokbd/fuji

polipo

What

socks5 proxy to http proxy

1. Linux

Install

apt-get install polipo

Configuration

$ cat /etc/polipo/config

logSyslog = true
logFile = /var/log/polipo/polipo.log
proxyAddress = "0.0.0.0"
proxyPort = 3128
socksParentProxy = "127.0.0.1:9999"
socksProxyType = socks5
allowedClients = 127.0.0.1

Start

service start polipo

2. MacOS

Install

brew install polipo

Start

polipo socksParentProxy=localhost:9999

3. examples

git config --global http.proxy 127.0.0.1:8123
git config --global --unset-all http.proxy