2016年6月29日 星期三

SCP 指令

<SCP 傳送檔案>
pi@f1:~/smile$ scp office.txt pi@f4:~ <傳送到f4 host pi的home directory>
pi@f4's password:
office.txt                                      0%    0     0.0KB/s   --:--
office.txt                                    100%   55     0.1KB/s   00:00

<Verify it is completed>
pi@f4:~$ ls
office.txt  smile  test.txt

pi@f1:~$ scp -r smile pi@f4:~ <SCP 傳送整個目錄>
pi@f4's password:
office.txt                                      0%    0     0.0KB/s   --:-- office.txt                                    100%   55     0.1KB/s   00:00
office2.txt                                     0%    0     0.0KB/s   --:-- office2.txt                                   100%   55     0.1KB/s   00:00

 <Verify it is completed>

<SCP 抓取檔案>
pi@f1:~$ scp pi@f4:~/f4test.txt ~
pi@f4's password:
f4test.txt                                      0%    0     0.0KB/s   --:-- f4test.txt                                    100%   22     0.0KB/s   00:00
pi@f1:~$ ls
0626  auto.sh  f4test.txt  hello  smile  test.txt
pi@f1:~$ cat f4test.txt
abcd1234567890

<SCP 抓取整個目錄>
pi@f1:~/f4$ scp -r pi@f4:~/smile ~/f4
pi@f4's password:
office.txt                                      0%    0     0.0KB/s   --:-- office.txt                                    100%   55     0.1KB/s   00:00
office                                          0%    0     0.0KB/s   --:-- office                                        100%   12     0.0KB/s   00:00
office2.txt                                     0%    0     0.0KB/s   --:-- office2.txt                                   100%   55     0.1KB/s   00:00

樹莓派產生 SSH 自動登入憑證

<產生 SSH 自動登入憑證>
pi@f1:~$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
Generating public/private dsa key pair.
Created directory '/home/pi/.ssh'.
Your identification has been saved in /home/pi/.ssh/id_dsa.
Your public key has been saved in /home/pi/.ssh/id_dsa.pub.
The key fingerprint is:
f4:37:c8:9e:66:7b:af:23:59:9a:d1:a7:40:b2:13:54 pi@f1
The key's randomart image is:
+---[DSA 1024]----+
|         .E      |
|        .        |
|       ..        |
|       .oo..     |
|        S=+.o    |
|        o.ooo..  |
|         .=B o   |
|         o=.+    |
|          .o.+.  |
+-----------------+
pi@f1:~$

pi@f1:~/.ssh$ ll
總計 16
drwx------ 2 pi pi 4096  6月 26 06:32 .
drwxr-xr-x 3 pi pi 4096  6月 26 06:32 ..
-rw------- 1 pi pi  668  6月 26 06:32 id_dsa
-rw-r--r-- 1 pi pi  595  6月 26 06:32 id_dsa.pub

pi@f1:~$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

pi@f1:~$ ll .ssh
總計 20
drwx------ 2 pi pi 4096  6月 26 06:44 .
drwxr-xr-x 3 pi pi 4096  6月 26 06:39 ..
-rw-r--r-- 1 pi pi  595  6月 26 06:44 authorized_keys
-rw------- 1 pi pi  668  6月 26 06:32 id_dsa
-rw-r--r-- 1 pi pi  595  6月 26 06:32 id_dsa.pub


pi@f1:~$ cat ~/.ssh/authorized_keys
ssh-dss AAAAB3NzaC1kc3MAAACBANN4E8LhI4A8ymZEkq8vFZoBlNyb1jI5Mx2j53BzfKnMMqkWXxlCkJYkzkIqhuekqIfaCT8c3CARFZ9yMNNzU4hZKOiuU1xR3aKlCfec+wGfEYUgiCmTIL4q5qAs+kfz1LAs1swtPrlAFPb1VqN/WchXhmASeNUXLOMV5tgnfQDnAAAAFQCgeP6cJqjP6mtTA4/CUBSJdXPCqwAAAIBFRWzWiWV81hZzLEShn3qimV3e/SassWkjWhJzHk4tlpR5trM+r+Dj3F4XSPKN7VYOswQExdHYZVccyfG+AY8Yfr9mBTeL6ZxXbjykZVfaL+SJvg0I0ZXx/y6DqTpZ/EkJv8uLd9yQlN9RQw3U9Q3SYLFs4LNUVDN23f74WUQ4kgAAAIA8dED8VkbwCoc8C2xX7mSHr0e32jdqXaNms7z8GrxGZQdVUpApeW1SQqOPSLcRTcwPuvHZUvJs63cidvpketNvMBu8UXo/TCIFUs5EpPmkMZKFacSKVz7XfD4jmpVNfGpwZ//87gUwS9TYijGKNXOEAHFFGi+jrDAco7Hjv7w9Mw== pi@f1

pi@f1:~$ ssh f4 <try ssh 登入其他機器>
The authenticity of host 'f4 (172.20.110.153)' can't be established.
ECDSA key fingerprint is 30:98:7c:8a:39:81:34:83:7e:39:d4:c0:d8:44:7a:b3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'f4,172.20.110.153' (ECDSA) to the list of known hosts.
pi@f4's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Jun 26 03:54:09 2016 from f4
pi@f4:~$ exit <離開>

<登入後會產生known_hosts>
-rw-r--r-- 1 pi pi  666  6月 26 06:47 known_hosts

pi@f1:~$ cat .ssh/known_hosts
|1|J2Ks8jCrK/nLOFpA27MyXeoj/ho=|As8PbHWM6YKa1fyu4qr+kV2EYPw= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLYJk9xZfu4nHqTLJy/F6pQmDNKKlicBBnsxKxqCCdH7afRnoRXBOpACtnotzfus2psEvUA2F5nbLfJ9DyHdt0M=
|1|Duy20DuhPYqmit8qz2M/hfV6Dhk=|CFhZWRA2Y/UJ1wqmqgO7M6x5xNQ= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBA5/f97V1+fk5xveLVn1x916k8H1GibsLHrW0bfTV2tZlecyYUo1w6PMdg+E1rIzQk7n/A6wi5eFej3y9I6ScMI=
|1|WaSnEvzy76uymZJyK+mBTN2reaI=|ycGjSFE7pAQby2CyFiITBBGwFOM= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBA5/f97V1+fk5xveLVn1x916k8H1GibsLHrW0bfTV2tZlecyYUo1w6PMdg+E1rIzQk7n/A6wi5eFej3y9I6ScMI=

利用SCP指領抓取憑證
<<ssh login without password work.>> 交憑証ssh login不用password

<先backup>
cp authorized_keys authorized_keys_bak

<從其他host copy來authorized_keys file>
scp pi@f2:~/.ssh/authorized_keys ~


pi@f1:~$ cat authorized_keys
ssh-dss AAAAB3NzaC1kc3MAAACBALhK3oOhL452rLWR1qGzAP99hNpne+/ZzzKNNPiiqxI2Ruxy3N4O1ausvqQF89M9AGt8MHmCyvMd+/HXzzUIuNEh1+cMLmXyNfdAPGHd0GiLoC/thXR8WQHgutY37w1LovMgDhoBR518j2pKTdwyMGgkeXUlwluVkJBdLImoDhOdAAAAFQCTOyOkWJWtXcuyd/DhXlh65r8PWQAAAIEAiGr5CWPbz5OK0wUjgaftZ/H4FctGF1c+aA9oEnvdClkBxRI0HstRfylrZOdyLt6Iz/J4A7uS+wGDNyr4QFHLrap+pmm/bVHNy3y4PGCgGWPJYAHeEhtkSp3wrf5w0jjWrupj2vfe8JZR3UqsrrSTieRrdWcpVTDBQtCd0fqnmFkAAACBAKFF6v/3SdnExgVpHlvfrCGkCKvpgdonrJHELKF8xkzfOfeY9PR5wk+5ErqWWTO/l0dGL/q8h1Y1G/63NBOw/Enhfh+YuqTHtZWqWC9weHR1mjERvoCj3HcHwrV2S84838+Et54mfImLKvcB0FJ0HnvsY4VvwjoJHXjUPTMmK7pj pi@f2 <這是f2的authorized_keys>

<cat and import到f2的 authorized_keys file>
pi@f1:~$ cat ~/authorized_keys >> ~/.ssh/authorized_keys


<check f2 f4的都進來了>
pi@f1:~/.ssh$ cat authorized_keys
ssh-dss AAAAB3NzaC1kc3MAAACBANN4E8LhI4A8ymZEkq8vFZoBlNyb1jI5Mx2j53BzfKnMMqkWXxlCkJYkzkIqhuekqIfaCT8c3CARFZ9yMNNzU4hZKOiuU1xR3aKlCfec+wGfEYUgiCmTIL4q5qAs+kfz1LAs1swtPrlAFPb1VqN/WchXhmASeNUXLOMV5tgnfQDnAAAAFQCgeP6cJqjP6mtTA4/CUBSJdXPCqwAAAIBFRWzWiWV81hZzLEShn3qimV3e/SassWkjWhJzHk4tlpR5trM+r+Dj3F4XSPKN7VYOswQExdHYZVccyfG+AY8Yfr9mBTeL6ZxXbjykZVfaL+SJvg0I0ZXx/y6DqTpZ/EkJv8uLd9yQlN9RQw3U9Q3SYLFs4LNUVDN23f74WUQ4kgAAAIA8dED8VkbwCoc8C2xX7mSHr0e32jdqXaNms7z8GrxGZQdVUpApeW1SQqOPSLcRTcwPuvHZUvJs63cidvpketNvMBu8UXo/TCIFUs5EpPmkMZKFacSKVz7XfD4jmpVNfGpwZ//87gUwS9TYijGKNXOEAHFFGi+jrDAco7Hjv7w9Mw== pi@f1
ssh-dss AAAAB3NzaC1kc3MAAACBAOrR8YAsS+7oNa9dzKKXnZ4jLJ8BRqMFPyUFoQ84G4TiT0nwFlU0+lE1JEVDV5NZP1j0IkwEg8SI9BVzQjX5xJb6+++2pR1uA/w60Z/dflxEkiJyKHLQwPsjOoNHZiEU7/FggMXioTZgrcqdvmOFp8ZYK4qq+aKU+G/5QMuBr5I7AAAAFQC3YT1QJb/BGoRhwo9gaN2c9jpFCQAAAIEA3S740E+OCCB0E3zgrbRuZ+5GfqOshKTZDw3LiJJzP/UQoN0JmwCtpiM1GMkvOY/VM856H1XIAtgolfdqy55o1JdJouRp8zBbIqJXq1VGn0NPZpQw47FFWLJWscOW6UnJywv39cMeHJ2oVccga0Q0fXE/ThK/uOF6An3egwrzA10AAACAcZQwL9svB5Wvgb8QYHaGGiAmkbHgUcs1kb5M9R5+Q1wrTLa7LuSJsr2HgNNkHGiIkaJUZMbZU5aJnb3uBSudls+DRn+khUrVkxDVPBvl3OwKGXlwUgQrFjctx5/MRN/khITwKNd+jEXub+if+ZrIAR4/RfY5Qe3qWOMAreDenDQ= pi@f4
ssh-dss AAAAB3NzaC1kc3MAAACBALhK3oOhL452rLWR1qGzAP99hNpne+/ZzzKNNPiiqxI2Ruxy3N4O1ausvqQF89M9AGt8MHmCyvMd+/HXzzUIuNEh1+cMLmXyNfdAPGHd0GiLoC/thXR8WQHgutY37w1LovMgDhoBR518j2pKTdwyMGgkeXUlwluVkJBdLImoDhOdAAAAFQCTOyOkWJWtXcuyd/DhXlh65r8PWQAAAIEAiGr5CWPbz5OK0wUjgaftZ/H4FctGF1c+aA9oEnvdClkBxRI0HstRfylrZOdyLt6Iz/J4A7uS+wGDNyr4QFHLrap+pmm/bVHNy3y4PGCgGWPJYAHeEhtkSp3wrf5w0jjWrupj2vfe8JZR3UqsrrSTieRrdWcpVTDBQtCd0fqnmFkAAACBAKFF6v/3SdnExgVpHlvfrCGkCKvpgdonrJHELKF8xkzfOfeY9PR5wk+5ErqWWTO/l0dGL/q8h1Y1G/63NBOw/Enhfh+YuqTHtZWqWC9weHR1mjERvoCj3HcHwrV2S84838+Et54mfImLKvcB0FJ0HnvsY4VvwjoJHXjUPTMmK7pj pi@f2

<把新的組合authorized_keys scp到其他host>
pi@f1:~/.ssh$ scp /home/pi/.ssh/authorized_keys pi@f2:~/.ssh
pi@f1:~/.ssh$ scp /home/pi/.ssh/authorized_keys pi@f4:~/.ssh
authorized_keys                                 0%    0     0.0KB/s   --:--
authorized_keys                               100% 1785     1.7KB/s   00:00

<認識ssh不用password>
pi@f1:~/.ssh$ ssh f2
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Jun 26 09:35:54 2016 from f1



更新樹莓派

下載最新的套件

rroot@f1:/etc/network# apt-get update
下載:1 http://archive.raspberrypi.org jessie InRelease [13.2 kB]
下載:2 http://mirrordirector.raspbian.org jessie InRelease [14.9 kB]
下載:3 http://archive.raspberrypi.org jessie/main armhf Packages [144 kB]
下載:4 http://mirrordirector.raspbian.org jessie/main armhf Packages [8,980                      kB]
下載:5 http://archive.raspberrypi.org jessie/ui armhf Packages [8,966 B]
6% [3 Packages gzip 0 B] [4 Packages 350 kB/8,980 kB 4%] [5 Packages 0 B/8,9                                                                                                                                                                                                                       下載:6 http://mirrordirector.raspbian.org jessie/contrib armhf Packages [37.                     5 kB]
略過 http://mirrordirector.raspbian.org jessie/contrib Translation-zh
略過 http://mirrordirector.raspbian.org jessie/contrib Translation-en
略過 http://mirrordirector.raspbian.org jessie/main Translation-zh_TW
略過 http://mirrordirector.raspbian.org jessie/main Translation-zh
略過 http://mirrordirector.raspbian.org jessie/main Translation-en
略過 http://mirrordirector.raspbian.org jessie/non-free Translation-zh_TW
略過 http://mirrordirector.raspbian.org jessie/non-free Translation-zh
略過 http://mirrordirector.raspbian.org jessie/non-free Translation-en
略過 http://mirrordirector.raspbian.org jessie/rpi Translation-zh_TW
略過 http://mirrordirector.raspbian.org jessie/rpi Translation-zh
略過 http://mirrordirector.raspbian.org jessie/rpi Translation-en
取得 9,271 kB 用了 34s (268 kB/s)
正在讀取套件清單... 完成
38% [4 Packages 3,327 kB/8,980 kB 37%] [等待標頭]


root@f1:/etc/network# apt-get upgrade
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
籌備升級中... 完成
下列套件將會維持其原有版本:
  libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc libraspberrypi0
  raspberrypi-bootloader
下列套件將會被升級:
  apt apt-utils bind9-host ca-certificates cpio curl dmsetup dpkg dpkg-dev
  file firmware-atheros firmware-brcm80211 firmware-libertas firmware-ralink
  firmware-realtek gnupg gpgv initramfs-tools isc-dhcp-client isc-dhcp-common
  krb5-locales libapt-inst1.5 libapt-pkg4.12 libbind9-90 libc-bin libc-dev-bin
  libc6 libc6-dbg libc6-dev libcurl3 libdevmapper1.02.1 libdns-export100
  libdns100 libdpkg-perl libdrm2 libexpat1 libgcrypt20 libgssapi-krb5-2
  libhogweed2 libidn11 libirs-export91 libisc-export95 libisc95 libisccc90
  libisccfg-export90 libisccfg90 libk5crypto3 libkrb5-3 libkrb5support0
  liblwres90 libmagic1 libnettle4 libpam-modules libpam-modules-bin
  libpam-runtime libpam0g libpcre3 libpng12-0 libpng12-dev libssh2-1
  libssl1.0.0 libsystemd0 libtalloc2 libtasn1-6 libudev1 libwbclient0
  libxapian22 libxml2 locales login multiarch-support openssh-client
  openssh-server openssh-sftp-server openssl passwd perl perl-base
  perl-modules python-rpi.gpio raspi-config rsyslog samba-common ssh sudo
  systemd systemd-sysv tzdata udev
升級 89 個,新安裝 0 個,移除 0 個,有 5 個未被升級。
需要下載 54.0 MB 的套件檔。
此操作完成之後,會多佔用 919 kB 的磁碟空間。
Do you want to continue? [Y/n]

(讀取資料庫 ... 目前共安裝了 30217 個檔案和目錄。)
Preparing to unpack .../tzdata_2016d-0+deb8u1_all.deb ...
Unpacking tzdata (2016d-0+deb8u1) over (2015f-0+deb8u1) ...
...
安裝新版的設定檔 /etc/init.d/raspi-config ...
Processing triggers for initramfs-tools (0.120+deb8u2) ...
Processing triggers for libc-bin (2.19-18+deb8u4) ...
Processing triggers for ca-certificates (20141019+deb8u1) ...
Updating certificates in /etc/ssl/certs... 19 added, 18 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.
Processing triggers for systemd (215-17+deb8u4) ..

完成check
root@f1:/etc# apt-get install nano wget tree python
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
nano 已經是最新版本了。
python 已經是最新版本了。
wget 已經是最新版本了。
下列【新】套件將會被安裝:
  tree
升級 0 個,新安裝 1 個,移除 0 個,有 5 個未被升級。
需要下載 44.9 kB 的套件檔。
此操作完成之後,會多佔用 96.3 kB 的磁碟空間。
Do you want to continue? [Y/n] Y
下載:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main tree armhf 1.7.0-3 [44.9 kB]
取得 44.9 kB 用了 1s (38.2 kB/s)
選取了原先未選的套件 tree。
(讀取資料庫 ... 目前共安裝了 30239 個檔案和目錄。)
Preparing to unpack .../tree_1.7.0-3_armhf.deb ...
Unpacking tree (1.7.0-3) ...
Processing triggers for man-db (2.7.0.2-5) ...
設定 tree (1.7.0-3) ...

基本樹莓派設定



pi@raspberrypi:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.3G  931M  262M  79% /
devtmpfs        214M     0  214M   0% /dev
tmpfs           218M     0  218M   0% /dev/shm
tmpfs           218M  4.4M  213M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           218M     0  218M   0% /sys/fs/cgroup
/dev/mmcblk0p1   60M   20M   41M  34% /boot

組態設定:
pi@raspberrypi:~$ sudo raspi-config

1 Expnad Filesystem ps. have to reboot system to enable
5->I1 Select en_US.UTF-8, zh_TW BIG5 and UTF-8
9->A3 Config GPU setting
8 Overclock Config CPU workload
Finish to reboot system


┌─────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├───────│──┐                                                                       │
│    1 Expand Filesystem              Ensures that all of the SD card s    │
│    2 Change User Password           Change password for the default u    │
│    3 Boot Options                   Choose whether to boot into a des    │
│    4 Wait for Network at Boot       Choose whether to wait for networ    │
│    5 Internationalisation Options   Set up language and regional sett    │
│    6 Enable Camera                  Enable this Pi to work with the R    │
│    7 Add to Rastrack                Add this Pi to the online Raspber    │
│    8 Overclock                      Configure overclocking for your P    │
│    9 Advanced Options               Configure advanced settings          │
│    0 About raspi-config             Information about this configurat    │
│                                                                          │
│                                                                          │
│                     <Select>                     <Finish>                │
│                                                                          │
└──────────────────────────────────────────────────────────────────────────────┘


┌──────────────────────────────────────────────────────────┐
          │ Chose overclock preset                                   │
          │                                                          │
          │ None   700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt │
          │ Modest 800MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt │
          │ Medium 900MHz ARM, 250MHz core, 450MHz SDRAM, 2 overvolt │
          │ High   950MHz ARM, 250MHz core, 450MHz SDRAM, 6 overvolt │
          │ Turbo  1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt│
          │ Pi2    1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt│
          │ Root partition has been resized.                         │
          │ The filesystem will be enlarged upon the next reboot



Package configuration
 ┌──────────────────────────┤ Configuring locales ├──────────────────────────│ Many packages in Debian use locales to display text in the correct      │
 │ language for the user. You can choose a default locale for the system   │
 │ from the generated locales.                                             │
 │                                                                         │
 │ This will select the default language for the entire system. If this    │
 │ system is a multi-user system where not all users are able to speak the   │ default language, they will experience difficulties.                    │
 │                                                                         │
 │ Default locale for the system environment:                              │
 │                                                                         │
 │                                None                                     │
 │                                C.UTF-8                                  │
 │                                en_GB.UTF-8                              │
 │                                en_US.UTF-8                              │
 │                                zh_TW                                    │
 │                                zh_TW.UTF-8                              │
 │                                                                         │
 │                                                                         │
 │                    <Ok>                        <Cancel>     


How much memory should the GPU have?  e.g. 16/32/64/128/256
Default = 0 用不到

┌──────────────────────────────────────────────────────────┐
          │ Chose overclock preset                                   │
          │                                                          │
          │ None   700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt │
          │ Modest 800MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt │
          │ Medium 900MHz ARM, 250MHz core, 450MHz SDRAM, 2 overvolt │
          │ High   950MHz ARM, 250MHz core, 450MHz SDRAM, 6 overvolt │
          │ Turbo  1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt│
          │ Pi2    1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt│

CPU Overclock as High


pi@raspberrypi:~$ df -h
檔案系統        容量  已用  可用 已用% 掛載點
/dev/root       3.6G  933M  2.5G   27% /
devtmpfs        214M     0  214M    0% /dev
tmpfs           218M     0  218M    0% /dev/shm
tmpfs           218M  4.4M  213M    2% /run
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           218M     0  218M    0% /sys/fs/cgroup
/dev/mmcblk0p1   60M   20M   41M   34% /boot
pi@raspberrypi:~$


Config Networking Setting

/etc/hostname
root@raspberrypi:/etc# more hostname
f1

/etc/hosts
root@raspberrypi:/etc# more hosts
127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1       f1
172.20.110.150  f1
172.20.110.151  f2
172.20.110.152  f3
172.20.110.153  f4


/etc/network/interfaces
auto lo
iface lo inet loopback

#iface eth0 inet manual

auto eth0
iface eth0 inet static
address 172.20.110.150
netmask 255.255.0.0
gateway 172.20.110.254
dns-nameservers 168.95.1.1
#
allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


/etc/resolv.conf
# Generated by resolvconf
nameserver 172.20.110.254
nameserver 168.95.1.1


加入無線AP基地台設定 for 1st machine only
$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

改ssid
psk

network={
        ssid="LOGTEAM"
        psk="log28353953"
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP
        auth_alg=OPEN


Enable ip forward 功能
$ sudo nano /etc/rc.local
加2行
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

2016年6月19日 星期日

Linux 指令小復習

Linux不用副檔名
r: read
w: write
x: execute

drwxr-xr-x 3 pi   pi   4096 Nov 21 22:55 .
drwxr-xr-x 3 root root 4096 Nov 21 20:32 ..
-rw-r--r-- 1 pi   pi      0 Nov 21 22:13 return

directory-Owner-Group-Others

pi@raspberrypi:~$ ls -al
total 28
drwxr-xr-x 3 pi   pi   4096 Nov 21 22:55 .
drwxr-xr-x 3 root root 4096 Nov 21 20:32 ..
-rw------- 1 pi   pi   1949 Nov 21 22:22 .bash_history
-rw-r--r-- 1 pi   pi    220 Nov 21 20:32 .bash_logout
-rw-r--r-- 1 pi   pi   3512 Nov 21 20:32 .bashrc
-rw-r--r-- 1 pi   pi      0 Nov 21 22:13 popd
-rw-r--r-- 1 pi   pi    675 Nov 21 20:32 .profile
drwxr-xr-x 2 pi   pi   4096 Nov 21 22:55 raspberrypi
-rw-r--r-- 1 pi   pi      0 Nov 21 22:13 return
-rw-r--r-- 1 pi   pi      0 Nov 21 22:13 source
-rw-r--r-- 1 pi   pi      0 Nov 21 22:13 times
-rw-r--r-- 1 pi   pi      0 Nov 21 22:13 true


root@f1:/etc# more passwd <查看檔案內容>
root@f1:/etc# cat passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin

pi@f1:~$ head -n 2 /etc/passwd <查看檔案前二行內容>
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin

pi@f1:~$ tail -n 2 /etc/passwd <查看檔案後二行內容>
ntp:x:107:112::/home/ntp:/bin/false
statd:x:108:65534::/var/lib/nfs:/bin/false

pi@f1:~$ alias <查詢自定命令>
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias ls='ls --color=auto'

pi@f2:~$ sudo ping f1 -c 4 <ping 4個package 自動停>
PING f1 (172.20.110.150) 56(84) bytes of data.
64 bytes from f1 (172.20.110.150): icmp_seq=1 ttl=64 time=0.172 ms
64 bytes from f1 (172.20.110.150): icmp_seq=2 ttl=64 time=0.189 ms
64 bytes from f1 (172.20.110.150): icmp_seq=3 ttl=64 time=0.151 ms
64 bytes from f1 (172.20.110.150): icmp_seq=4 ttl=64 time=0.151 ms

pi@f1:~$ alias ping='sudo ping -c 4' <自訂命令>

pi@f1:~$ ping 172.20.110.254 <test自訂命令生效>
PING 172.20.110.254 (172.20.110.254) 56(84) bytes of data.
64 bytes from 172.20.110.254: icmp_seq=1 ttl=64 time=0.497 ms
64 bytes from 172.20.110.254: icmp_seq=2 ttl=64 time=0.426 ms
64 bytes from 172.20.110.254: icmp_seq=3 ttl=64 time=0.460 ms
64 bytes from 172.20.110.254: icmp_seq=4 ttl=64 time=0.464 ms

--- 172.20.110.254 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.426/0.461/0.497/0.036 ms

pi@f1:~$ alias <查看自訂的命令>
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias ls='ls --color=auto'
alias ping='sudo ping -c 4' <自訂的>

pi@f1:~$ unalias ping <移除自訂命令>

pi@f1:~$ alias dir='ls -al'
pi@f1:~$ alias ll='ls -al'
pi@f1:~$ dir
總計 28
drwxr-xr-x 2 pi   pi   4096 11月 21  2015 .
drwxr-xr-x 3 root root 4096 11月 21  2015 ..
-rw------- 1 pi   pi    294  6月 26 03:26 .bash_history
-rw-r--r-- 1 pi   pi    220 11月 21  2015 .bash_logout
-rw-r--r-- 1 pi   pi   3512 11月 21  2015 .bashrc
-rw-r--r-- 1 pi   pi    675 11月 21  2015 .profile
-rw-r--r-- 1 pi   pi     43 11月 21  2015 test.txt
pi@f1:~$ ll
總計 28
drwxr-xr-x 2 pi   pi   4096 11月 21  2015 .
drwxr-xr-x 3 root root 4096 11月 21  2015 ..
-rw------- 1 pi   pi    294  6月 26 03:26 .bash_history
-rw-r--r-- 1 pi   pi    220 11月 21  2015 .bash_logout
-rw-r--r-- 1 pi   pi   3512 11月 21  2015 .bashrc
-rw-r--r-- 1 pi   pi    675 11月 21  2015 .profile
-rw-r--r-- 1 pi   pi     43 11月 21  2015 test.txt

pi@f1:~$ free -mh <查看記憶體>
             total       used       free     shared    buffers     cached
Mem:          434M       368M        65M       4.4M        35M       292M
-/+ buffers/cache:        40M       393M
Swap:          99M         0B        99M

pi@f1:~$ echo Max New Line <回聲 echo>
Max New Line
pi@f1:~$ echo -n Max NO New Line
Max NO New Linepi@f1:~$


 pi@f1:~$ nano hello <利用nano寫一個bash file>
echo -n hello!
echo how are you

<Save 但權限不能run>
-bash: ./hello: 拒絕不符權限的操作
-rw-r--r-- 1 pi   pi     33  6月 26 05:35 hello

pi@f1:~$ chmod +x hello

pi@f1:~$ ./hello
hello!how are you


pi@f1:~$ nano auto.sh <利用nano寫一個系統維運指令-1><以後重開機可以執行就有習慣指令環境>
#!/bin/bash
alias ll='ls -al'
alias dir='ls -al'
alias reboot='sudo reboot'
alias bye='sudo shutdown -h now'
alias ping='sudo ping -c 4'

. auto.sh <run auto.sh 套用以上alias>

再寫入home directory .bashrc file

nano ~/.bashrc

......
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
. ~/auto.sh
<加在file end>

reboot and verify enable okay.


pi@f1:~$ cat hello > 0626 <output overwrite to 0626 覆寫>
pi@f1:~$ more 0626
echo -n hello!
echo how are you
pi@f1:~$ cat hello >> 0626 <output do NOT overwrite to 0626 增加新行>
pi@f1:~$ more 0626
echo -n hello!
echo how are you
echo -n hello!

第一次樹莓派




Start
Launch Win32DiskImager
Burn Image to SD card - 2015-11-21-raspbian-jessie-lite.img
Install driver for UART - CP210xVCPInstaller_x64
Check Drivers Manager -Silicon Labs CP210x USB to UART Bridge (COM3)
Connect to little blade by Putty
Serial, COM3, Speed:115200
Opne and Login by pi/raspberry

Raspbian GNU/Linux 8 raspberrypi ttyAMA0

raspberrypi login: pi
Password:raspberry <盲打>

Login incorrect
raspberrypi login: pi
Password:
Last login: Sat Nov 21 22:14:17 UTC 2015 on ttyAMA0
Linux raspberrypi 4.1.13+ #826 PREEMPT Fri Nov 13 20:13:22 GMT 2015 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
pi@raspberrypi:~$


pi@raspberrypi:~$ sudo su root <切換 Root>
root@raspberrypi:/home/pi#


<其他指令和Linux差不多>

check_systemv1.1

 check_systemv1.1.bat 可用於電腦資產盤點 @echo off REM 後續命令使用的是:UTF-8編碼 chcp 65001 echo ***Thanks for your cooperation*** echo ***感謝你的合作*** timeout 1...