2015年5月6日 星期三

Ubuntu 網卡設定DHCP


  1. sudo  vim /etc/network/interfaces
  2. 將 iface eth0 inet static 改成 iface eth0 inetdhcp
  3. sudo /etc/init.d/networking restart
VirtualBox就重開機一下吧。
PS. 如果你有第二張網卡 





auto eth1
iface eth1 inetdhcp


PS. 如果想用固定IP
#Class C 設法
iface eth0 inet static 
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1


資料來源:
  • http://askubuntu.com/questions/446183/how-to-set-up-nat-and-host-only-networking-with-static-ip-address-in-virtualbox

2015年5月5日 星期二

Ubuntu SSH install

SSH Server目的:

  讓linux系統可以利用SSH機制被遠端操作 (使用公私鑰機制驗證)。

  備註1:以下命令已經切換至 root, 若沒有切換至root,記得在命令前面加sudo。


1. 查詢套件安裝狀況
  • dpkg -l | grep ssh
      如果只有看到 openssh-client,就是還沒安裝 SSH server。


2. 查詢 ssh 是否有在運作的指令
  • netstat -a | grep ssh
如果看到
tcp    0  0  *:ssh     *:*     LISTEN
tcp6  0  0  [::]:ssh  [::]:*   LISTEN

表示ssh有在運作


3. 關閉 ssh
  • service ssh stop
4.啟動 ssh
  • service ssh start
5.重啟 ssh
  • service ssh restart

6. 安裝 ssh
  • apt-get upudate    //更新套件清單
  • apt-get install ssh

7.用戶端SSH金鑰
  •  key會在家目錄的.ssh 
  • .ssh可看到  id_ras 、 id_ras.pub。  
  • id_ras 是私鑰,這個不可以給別人。
  • id_ras.pub 是公鑰,這是要給ssh服務的伺服器用的。
8. 上傳公鑰到目標伺服器
  • ssh-copy-id -i id_ras.pub  [登入帳號]@[位置]  // 記得 -i  不加會找錯key
      在mac中如果沒有ssh-copy-id指令,有兩種選擇:
    
         a. brew install ssh-copy-id 安裝命令
     
         b. 用scp 上傳 public key

             1. 在serve端  ~/ 建立 .ssh資料夾。
                  cd ~/
                  mkdir .ssh

             2. 在client電腦將公開金鑰上傳
                 scp id_ras.pub [登入帳號]@[位置]:/home/[帳號名稱]/.ssh/authorized_keys

9. 更改 authorized_keys 權限
  • chmod go-w ~/
  • chmod 700 ~/.ssh
  • chmod 600 ~/.ssh/authorized_keys

10.關閉帳號密碼登入
  •  sudo vim /etc/ssh/sshd_config
  • 將 PermitRootLogin without-password 改成 PermitRootLogin no
  • 取消註解 AuthorizedKeysFile      %h/.ssh/authorized_keys
  • PasswordAuthentication yes 改 PasswordAuthentication no  //關閉遠端帳號密碼登入



11.  ssh連線
  • ssh [登入帳號]@[位置



參考資料:
  • https://help.ubuntu.com/14.04/serverguide/openssh-server.html
  • https://help.ubuntu.com/community/SSH/OpenSSH/Configuring
  • https://help.ubuntu.com/community/SSH/OpenSSH/Keys
  • http://blog.crboy.net/2012/05/ssh-security-note.html

history

功能:查詢下過的命令

範例:
  • history
  • history | grep wget    //在history中過濾出所有的 wget指令

linux ps aux

功能:查詢 Linux 系統上服務是否有在運行

範例:
  • ps aux | grep tomcat
  • ps aux | grep ssh

linux locale

1. 查詢機器上已經安裝的語系
  •  locale -a
2.編輯 local文件
  • sudo vim /var/lib/locales/supported.d/local
  • 文件中加入 zh_TW.UTF-8 UTF-8
  • 離開vim
3.加入語系
  • sudo locale-gen

後記:
      為什麼要設定local,因為當你 tomcat utf-8 設定都設了,程式也沒問題,html宣告也對了,DB設定也對了,但寫入db的中文不對勁,那就是最底層的linux語系缺少zh_TW.UTF-8造成的。


參考資料:
  • http://tutul.logdown.com/posts/2014/08/13/ubuntu-server-12-04-lts-change-language
  • http://www.arthurtoday.com/2009/11/ubuntu-locale.html

2014年9月26日 星期五

mac connect aws ec2

1.  Amaon EC2  建立機器實體後,會產生一個  pem key,這個pem要保存好,不見的話救不回來。


2.  打開mac 終端機,進入pem所在資料夾


3.  pme 需要修改權限
  • chmod 400 xxx.pem
忘了修改權限會發生如下警訊:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'xxx.pem' are too open.

4.  連線
  • ssh -i   [your pem name].pem ubuntu@[your public DNS]



關於SSH

2014年9月13日 星期六

Intellij scala

1. down load intellij 

2. install scala plugin

  • open intellj
  • select   ->   Configure  ->  Plugins
  • search scala
  • install plugin


3. install sbt plugin

  • Configure -> Plugins
  • search sbt
  • install plugin
5. create scala project
  • Create New Project
  • Scala -> SBT
  • Enter Project Name

Note :  if  your sbt  console  has  error  message
           
      Error  :  Cannot determine Java VM executable in selected JDK

      Resolve :
  • Configure -> Project defaults -> Project structure and add the jdk.
  • Configure -> Preferences -> IDE Settings -> Scala  andd the jdk.
  • File -> Project structure  add the jdk.

             JDK  Patch :
              /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home




reference document :