2016年9月8日 星期四

ubuntu 增加有admin權限的使用者帳戶


建立帳戶
adduser allie

接下來就會有一些資訊,填完之後就會自動建立好home dir


要讓帳戶可以使用sudo
sudo usermod -a -G sudo hduser



收工

ubuntu change hostname

vagrant@vagrant:/$ sudo vim /etc/hostname




















vagrant@vagrant:/$ sudo vim /etc/hosts




















vagrant@vagrant:/$ sudo reboot now

2016年9月7日 星期三

架設Apache及vsftpd設定


Install apache2

sudo apt-get update
sudo apt-get install apache2
sudo apt-get install apache2 apache2-doc apache2-utils



若 sudo service apache2 restart 時出現
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

只要在/etc/apache2/apache2.conf加入
ServerName localhost
即可解決



Install & setting vsftpd

sudo apt-get update
sudo apt-get install vsftpd libpam-pwdfile


安裝好了之後,接下來要設定vsftp
本文設定為針對此目錄結構:


















假設www資料夾裡存放網站程式碼(html)及專案資料(ftp),
html目錄下會有許多專案 (以下以wiff為例),
每個專案裡會有一個使用者帳號,
只能存取自己專案資料夾裡的資料。


現在,假設資料夾都已經建好,
立馬開始進行vsftpd的設定:
sudo vim /etc/vsftpd.conf

進入編輯畫面之後,我們要注意的設定如下:
# 預設的情況下,要將使用者限制在自己的家目錄之內
chroot_local_user=YES
# 支援檔案上傳
write_enable=YES
# 為了讓透過 FTP 上傳的檔案的預設群組權限為「可寫入」
local_umask=002
# 支援local端登入使用
local_enable=YES
# 要求vsftpd讓使用者在對自己的家目錄有寫入的權限下仍然允許連線
allow_writeable_chroot=YES

接下來要設定pam(身份認證模組)
sudo vim /etc/pam.d/vsftpd

其實就是全部註解掉,然後加上passwd的設定2行
#Standard behaviour for ftpd(8).
auth   required        pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
#Note: vsftpd handles anonymous logins on its own. Do not enable pam_ftp.so.
#Standard pam includes
#@include common-account #註解掉
#@include common-session #註解掉
#@include common-auth #註解掉
#auth   required        pam_shells.so #註解掉


#下面兩行加上
auth    required pam_pwdfile.so pwdfile /etc/vsftpd.passwd
account required pam_permit.so

接下來建立FTP的使用者帳號
# 創造一個不能登入系統的帳號
sudo useradd -M  -s /usr/sbin/nologin htmlAdmin
sudo passwd htmlAdmin

# 第一次設定密碼需要先create htpasswd檔案 (HTTP基本認證的user帳密)
sudo htpasswd -cd /etc/vsftpd.passwd htmlAdmin 
# -c : Create the passwdfile.
# -d : Use crypt() encryption for passwords.
# ps. 如果要創第二組帳號的密碼,去掉-c (因為已經create過了)
# sudo htpasswd -d /etc/vsftpd.passwd user2

接下來設定資料夾,並幫帳號指定根目錄
sudo chmod 555 /var/www/
sudo chmod 755 /var/www/html/
sudo chown htmlAdmin:ftp -R /var/www/html/
sudo usermod --home /var/www/html/ htmlAdmin
sudo service vsftpd restart

好了,這樣應該就可以了~
開一下filezilla來試試看吧!

接下來要設定meteor和wiff 等等子資料夾的權限都跟下面一樣
sudo useradd -M -s /usr/sbin/nologin meteor
sudo passwd meteor
sudo htpasswd -d /etc/vsftpd.passwd meteor
sudo chmod 777 /var/www/html/meteor
sudo chown meteor:ftp -R /var/www/html/meteor/
sudo usermod --home /var/www/html/meteor meteor
sudo service vsftpd restart



最後,注意!切記!
如果要用filezilla來測試,
每次vsftpd restart之後要把filezilla整個關掉再開。



以上參考:
http://hong-s-note.logdown.com/posts/760695-tutorial-ubuntu-set-up-ftp-server-vsftpd
http://ifresh.cc/solution-to-vsftpd-refusing-to-run-with-writable-root-inside-chroot/





SSL(https)設定


現在的apache都已經有內建openssl了,
所以只要裝好apache之後,開啟SSL模組即可
sudo a2enmod ssl
接下來要建立金鑰,為了管理方便,
先建個資料夾,再把金鑰放進去。
sudo mkdir /etc/apache2/ssl
金鑰設定為365天後到期
sudo openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.key
金鑰產生過程會有一些額外資訊要求你填寫,
填寫完之後就算產生完成,
再接著設定apache,
讓預設的http和https都可以使用
sudo vim /etc/apache2/sites-available/000-default.conf
設定內容如下:
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        ServerName example.com:443
        DocumentRoot /var/www/html
        <Directory />
          Options FollowSymLinks
          AllowOverride None
       </Directory>
       <Directory /var/www/html/>
         Options Indexes FollowSymLinks MultiViews
         AllowOverride None
         Order allow,deny
         allow from all
      </Directory>

      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
      <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
      </Directory>
      #   SSL Engine Switch:
      #   Enable/Disable SSL for this virtual host.
      SSLEngine on

      #   A self-signed (snakeoil) certificate can be created by installing
      #   the ssl-cert package. See
      #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
      #   If both key and certificate are stored in the same file, only the
      #   SSLCertificateFile directive is needed.    
      SSLCertificateFile /etc/apache2/ssl/apache.pem
      SSLCertificateKeyFile /etc/apache2/ssl/apache.key

      ErrorLog ${APACHE_LOG_DIR}/error.log

      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel warn

      CustomLog ${APACHE_LOG_DIR}/access.log combined

      Alias /doc/ "/usr/share/doc/"
      <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
      </Directory>

    </VirtualHost>



重啟,搞定!
sudo service apache2 restart






2016年9月5日 星期一

VirtualBox+Vagran與ubuntu網路設定

Virtualbox+Vagrant


目標:快速架設好ubuntu,包含使用者


Virtualbox 與 Vagrant 至官網下載並照預設安裝後,

找一個地方建資料夾準備放Vagrantfile(vagrant的設定檔)。

Vagrantfile可重複建立多個virtualbox os。



接下來到Vagrant Cloud 搜尋想要的box,

這些box是別人整理好的直接灌之後就可以用,

也可以自己上傳。

這裡以ubuntu 14.04 LTS的desktop版本為例。






打開terminal,移動到剛剛建立要來放Vagrantfile的資料夾,

然後照著網頁指示輸入 vagrant init box-cutter/ubuntu1404-desktop;











建好的Vagrantfile出現之後就可以直接下 vagrant up

vagrant就會自動幫你灌好virtualbox的os




噹噹!灌好開好已!



















設定root密碼



由vagrant架好的os通常會預設帳號、密碼都是vagrant。


登入後搜尋並打開terminal輸入指令:sudo passwd root

就可以設定root密碼。

為了應付不時之需,早點設好吧XD


設好之後用su -登入試試看是否設定成功










網路設定


目標:ubuntu有固定IP,並可連上外部網路,且pietty可連入ubuntu


其實通常剛裝完的時候就已經有預設的NAT網路了,

但由於我們要架設的是SERVER,也需要使用putty/pietty來連線以方便操作,

必須有static ip,

所以才需要特別設定這一段網路的部份。


廢話不多說,快趁可以連外網的時候先裝好vim啊啊啊啊啊~~~

更新軟體清單:sudo apt-get update



安裝vim:sudo apt-get install vim


























裝好之後就先幫virtual os關機 準備正式開始設定吧!

首先要使用virtualbox來設定os的(偽)硬體網路










接下來設定軟體部份

本機網路IP:192.168.16.92

要設定給VirtualBox的IP:192.168.16.99

先用ifconfig來設定看看能不能通

sudo ifconfig eth0 192.168.16.99 netmask 255.255.255.0











確定可以通了之後再設到網路設定檔上

使用 root 權限打開 /etc/network/interfaces 檔案

sudo vim /etc/network/interfaces


輸入以下:
iface eth0 inet static
address 192.168.16.99
netmask 255.255.255.0
gateway 192.168.16.1
dns-nameservers 8.8.8.8









存檔後重新啟動網卡,然後ping看看是否可以與本機互通

ubuntu 14.04 LTS的重新啟動指令是sudo ifdown eth0 && sudo ifup eth0















































再ping本機看看、開網頁看看,確定都可以通之後就可以用pietty囉~(灑花

















































※以上許多參考: https://babu0628.wordpress.com/2013/01/09/ubuntu-virtual-box-%E7%B6%B2%E8%B7%AF%E5%B0%8D%E5%A4%96%E9%80%A3%E6%8E%A5%E8%A8%AD%E5%AE%9A/