2008年4月4日 星期五

檔案建立與群組目錄共享(SGID的使用):

實作範例:Each department(hr, web, sales) for which you created a group also needs a shared directory. This will allow users in each department to share files, but will prevent users in other department from altering, or even seeing those files.

只有相同群組的使用者具有進入群組目錄的權限,其餘使用者無,且相同使用者具有共享檔案的權限。


[root@server1 depts]# mkdir -p /depts/{sales,hr,web}

[root@server1 depts]# ls | grep -v tech | sed 's/^/chmod 770 /' | sh –x

+ chmod 770 hr

+ chmod 770 sales

+ chmod 770 web

[root@server1 depts]# ls | grep -v tech | sed 's/^/chmod g+s /' | sh -x

+ chmod g+s hr

+ chmod g+s sales

+ chmod g+s web


根據以上的設定,相同群組的用戶,將不用變更檔案的權限(permission),即可達到檔案共享的目的。

檔案存取清單(ACLs):

實作範例:Some data need to be accessible to several groups. Use ACLs to accomplish this. Create a new directory in /depts/ called tech. Change the permissions such that root is the owner and hr is the group. Use ACLs to give full permission for /depts/tech/ to the web group. Allow alex read/execute (but not write)permission on the /depts/tech/ directry. Set the default ACL of read/write for alex on that directory/


[root@server1 ~]# vi /etc/fstab

LABEL=/ / ext3 defaults,acl 1 1


[root@server1 ~]# mount

/dev/sda2 on / type ext3 (rw,acl)


[root@server1 depts]# setfacl -b tech

[root@server1 depts]# ll

total 32

drwxrws--- 2 root hr 4096 Jan 11 10:50 hr

drwxrws--- 2 root sales 4096 Jan 11 10:50 sales

drwxr-s--- 2 root hr 4096 Jan 11 13:55 tech

drwxrws--- 2 root web 4096 Jan 11 10:50 web

[root@server1 depts]# setfacl -m g:web:rwx tech

[root@server1 depts]# setfacl -m u:alex:rx tech

[root@server1 depts]# setfacl -m d:u:alex:rw tech

[root@server1 depts]# getfacl tech

[root@server1 depts]# getfacl tech/

# file: tech

# owner: root

# group: hr

user::rwx

user:alex:r-x

group::rwx

group:web:rwx

mask::rwx

other::---

default:user::rwx

default:user:alex:rw-

default:group::rwx

default:mask::rwx

default:other::---


ACLs為權限擴張的表現,在原本的權限下(root.hr rwxrwx---),另外提供web grouprwx權限,以及user alexrx權限,default ACLs的設定,讓alex有使用檔案的權限,無新建檔案的權限;其中user::rwx user:alex:r-x代表目錄的所有人具有rwx的權限之外,且用戶 alex具有列出目錄中的檔案與進入目錄的權限;group::rwx group:web:rwx代表原有的group hr外且web group同樣具有rwx的權限。


SETFACL(1) Access Control Lists SETFACL(1)

NAME

setfacl - set file access control lists

SYNOPSIS

setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ...

setfacl --restore=file


DESCRIPTION
This utility sets Access Control Lists (ACLs) of files and directories.
On the command line, a sequence of commands is followed by a sequence
of files (which in turn can be followed by another sequence of com-
mands, ...).

The options -m, and -x expect an ACL on the command line. Multiple ACL
entries are separated by comma characters (‘,’). The options -M, and -X
read an ACL from a file or from standard input. The ACL entry format is
described in Section ACL ENTRIES.

The --set and --set-file options set the ACL of a file or a directory.

The previous ACL is replaced. ACL entries for this operation must
include permissions.

The -m (--modify) and -M (--modify-file) options modify the ACL of a
file or directory. ACL entries for this operation must include permis-
sions.

The -x (--remove) and -X (--remove-file) options remove ACL enries.
Only ACL entries without the perms field are accepted as parameters,
unless POSIXLY_CORRECT is defined.

When reading from files using the -M, and -X options, setfacl accepts
the output getfacl produces. There is at most one ACL entry per line.

After a Pound sign (‘#’), everything up to the end of the line is
treated as a comment.

If setfacl is used on a file system which does not support ACLs, set-
facl operates on the file mode permission bits. If the ACL does not fit
completely in the permission bits, setfacl modifies the file mode per-
mission bits to reflect the ACL as closely as possible, writes an error
message to standard error, and returns with an exit status greater than
0.


PERMISSIONS
The file owner and processes capable of CAP_FOWNER are granted the
right to modify ACLs of a file. This is analogous to the permissions
required for accessing the file mode. (On current Linux systems, root
is the only user with the CAP_FOWNER capability.)


OPTIONS

-b, --remove-all
Remove all extended ACL entries. The base ACL entries of the owner,
group and others are retained.

-k, --remove-default
Remove the Default ACL. If no Default ACL exists, no warnings are
issued.

-n, --no-mask
Do not recalculate the effective rights mask. The default behavior
of setfacl is to recalculate the ACL mask entry, unless a mask
entry was explicitly given. The mask entry is set to the union of
all permissions of the owning group, and all named user and group
entries. (These are exactly the entries affected by the mask
entry).

--mask
Do recalculate the effective rights mask, even if an ACL mask entry
was explicitly given. (See the -n option.)

-d, --default
All operations apply to the Default ACL. Regular ACL entries in the
input set are promoted to Default ACL entries. Default ACL entries
in the input set are discarded. (A warning is issued if that hap-
pens).

--restore=file
Restore a permission backup created by ‘getfacl -R’ or similar. All
permissions of a complete directory subtree are restored using this
mechanism. If the input contains owner comments or group comments,
and setfacl is run by root, the owner and owning group of all files
are restored as well. This option cannot be mixed with other
options except ‘--test’.

--test
Test mode. Instead of changing the ACLs of any files, the resulting
ACLs are listed.

-R, --recursive
Apply operations to all files and directories recursively. This
option cannot be mixed with ‘--restore’.

-L, --logical
Logical walk, follow symbolic links. The default behavior is to
follow symbolic link arguments, and to skip symbolic links encoun-
tered in subdirectories. This option cannot be mixed with
‘--restore’.

-P, --physical
Physical walk, skip all symbolic links. This also skips symbolic
link arguments. This option cannot be mixed with ‘--restore’.

--version
Print the version of setfacl and exit.

--help
Print help explaining the command line options.

-- End of command line options. All remaining parameters are inter-
preted as file names, even if they start with a dash.

- If the file name parameter is a single dash, setfacl reads a list
of files from standard input.


ACL ENTRIES
The setfacl utility recognizes the following ACL entry formats (blanks
inserted for clarity):


[d[efault]:] [u[ser]:]uid [:perms]
Permissions of a named user. Permissions of the file owner if
uid is empty.

[d[efault]:] g[roup]:gid [:perms]
Permissions of a named group. Permissions of the owning group if
gid is empty.

[d[efault]:] m[ask][:] [:perms]
Effective rights mask

[d[efault]:] o[ther][:] [:perms]
Permissions of others.

Whitespace between delimiter characters and non-delimiter characters is
ignored.


Proper ACL entries including permissions are used in modify and set
operations. (options -m, -M, --set and --set-file). Entries without
the perms field are used for deletion of entries (options -x and -X).

For uid and gid you can specify either a name or a number.

The perms field is a combination of characters that indicate the per-
missions: read (r), write (w), execute (x), execute only if the file is
a directory or already has execute permission for some user (X).
Alternatively, the perms field can be an octal digit (0-7).


AUTOMATICALLY CREATED ENTRIES

Initially, files and directories contain only the three base ACL
entries for the owner, the group, and others. There are some rules that
need to be satisfied in order for an ACL to be valid:

* The three base entries cannot be removed. There must be exactly one
entry of each of these base entry types.

* Whenever an ACL contains named user entries or named group objects,
it must also contain an effective rights mask.

* Whenever an ACL contains any Default ACL entries, the three Default
ACL base entries (default owner, default group, and default others)
must also exist.

* Whenever a Default ACL contains named user entries or named group
objects, it must also contain a default effective rights mask.

To help the user ensure these rules, setfacl creates entries from
existing entries under the following conditions:

* If an ACL contains named user or named group entries, and no mask
entry exists, a mask entry containing the same permissions as the
group entry is created. Unless the -n option is given, the permis-
sions of the mask entry are further adjusted to include the union
of all permissions affected by the mask entry. (See the -n option
description).

* If a Default ACL entry is created, and the Default ACL contains no
owner, owning group, or others entry, a copy of the ACL owner, own-
ing group, or others entry is added to the Default ACL.

* If a Default ACL contains named user entries or named group
entries, and no mask entry exists, a mask entry containing the same
permissions as the default Default ACL’s group entry is added.
Unless the -n option is given, the permissions of the mask entry
are further adjusted to inclu de the union of all permissions
affected by the mask entry. (See the -n option description).


EXAMPLES
Granting an additional user read access
setfacl -m u:lisa:r file

Revoking write access from all groups and all named users (using the
effective rights mask)
setfacl -m m::rx file

Removing a named group entry from a file’s ACL
setfacl -x g:staff file

Copying the ACL of one file to another
getfacl file1 | setfacl --set-file=- file2

Copying the access ACL into the Default ACL
getfacl --access dir | setfacl -d -M- dir

CONFORMANCE TO POSIX 1003.1e DRAFT STANDARD 17
If the environment variable POSIXLY_CORRECT is defined, the default
behavior of setfacl changes as follows: All non-standard options are
disabled. The ‘‘default:’’ prefix is disabled. The -x and -X options
also accept permission fields (and ignore them).

AUTHOR
Andreas Gruenbacher, <a.gruenbacher@bestbits.at>.

Please send your bug reports, suggested features and comments to the
above address.

SEE ALSO
getfacl(1), chmod(1), umask(1), acl(5)

May 2000 ACL File Utilities SETFACL(1)

2008年1月16日 星期三

Service: Sendmail – grnericstable

前言

Sendmail提供重新編寫寄件者(The header of sander)的檔頭資料的功能,可以針對usernamedimainnameusername@domainname)個別進行資料重編,在建立Sendmail Sender Rewrite功能時先修改/etc/sendmail.mcSendmail開啟重新編寫郵件訊息中寄件者資料的功能,再建立寄件者資料對應資料庫(genericstable)與收件者對應資料庫(/etc/aliases)以讓收件者可以收發信件。


Key words: Sendmail, genericstable,


  1. 相關設定與調校

    1. 啟用寄件者資料重編功能:

修改/etc/sendmail.mc以啟用Sender write功能,在此一檔案中,以下的設定值必需是在MAILER( )之前;

FEATURE(`genericstable')dnl

FEATURE(always_add_domain)dnl

FEATURE(`generics_entire_domain')dnl

GENERICS_DOMAIN_FILE(`/etc/mail/local-host-names')dnl


# make –C /etc/mail

# service sendmail restart


    1. 建立寄件者資料對應資料庫(以myuser1為例):

[root@server1 mail]# cat > genericstable

myuser1 myuser1.alias@example.com

myuser2 myuser2.alias@example.com

[root@server1 mail]# makemap hash genericstable < genericstable


    1. 建立服務網域資料庫:

[root@server1 mail]# cat >> local-host-names

server1.example.com

example.com


    1. 建立收件者對應資料庫

[root@server1 mail]# cat >> /etc/aliases

myuser1.alias: myuser1

myuser2.alias: myuser2


[root@server1 mail]# newaliases

/etc/aliases: 80 aliases, longest 15 bytes, 848 bytes total


  1. 驗證

Local

[root@server1 mail]# su - myuser1

[myuser1@server1 ~]$ echo 'test alias' | mail -vs 'test' root@station5.example.com

root@station5.example.com... Connecting to [127.0.0.1] via relay...

220 server1.example.com ESMTP Sendmail 8.13.5/8.13.5; Thu, 17 Jan 2008 13:48:44 +0800

>>> EHLO server1.example.com

250-server1.example.com Hello localhost.localdomain [127.0.0.1], pleased to meet you

250-ENHANCEDSTATUSCODES

250-PIPELINING

250-8BITMIME

250-SIZE

250-DSN

250-ETRN

250-DELIVERBY

250 HELP

>>> MAIL From:<myuser1@server1.example.com> SIZE=56

250 2.1.0 <myuser1@server1.example.com>... Sender ok

>>> RCPT To:<root@station5.example.com>

>>> DATA

250 2.1.5 <root@station5.example.com>... Recipient ok

354 Enter mail, end with "." on a line by itself

>>> .

250 2.0.0 m0H5miI1025855 Message accepted for delivery

root@station5.example.com... Sent (m0H5miI1025855 Message accepted for delivery)

Closing connection to [127.0.0.1]

>>> QUIT

221 2.0.0 server1.example.com closing connection


Remote

[root@station5 root]# mutt

Date: Thu, 17 Jan 2008 13:48:44 +0800

From: myuser1.aliases@example.com

To: root@station5.example.com

Subject: test


test alias


回信驗證 /etc/aliases 的設定:

Date: Thu, 17 Jan 2008 14:20:50 +0800

From: root <root@station5.example.com>

To: myuser1.alias@example.com

Subject: Re: test

User-Agent: Mutt/1.2.5.1i

In-Reply-To: <200801170555.m0H5tevD025923@server1.example.com>; from

+myuser1.alias@example.com on Thu, Jan 17, 2008 at 01:55:40PM +0800


Alias is OK to go


On Thu, Jan 17, 2008 at 01:55:40PM +0800, myuser1.alias@example.com wrote:

> test alias

2008年1月13日 星期日

Security: The Pluggable Authentication Module (PAM) system

I.Module type

  1. auth

  2. account

  3. passwd

  4. session

II.Control flag

  1. required

  2. requested

  3. sufficient

  4. optional


實際範例 /etc/pam.d/login


[root@server1 pam.d]# cat /etc/pam.d/login

#%PAM-1.0

auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so

auth include system-auth

account required pam_nologin.so

account include system-auth

password include system-auth

# pam_selinux.so close should be the first session rule

session required pam_selinux.so close

session include system-auth

session required pam_loginuid.so

session optional pam_console.so

# pam_selinux.so open should only be followed by sessions to be executed in the user context

session required pam_selinux.so open

session optional pam_keyinit.so force revoke


實際範例 – 自訂PAM (限制特定的使用者存取檔案)

模組檔存放位置:/lib/security/pam_listfile.so

模組檔說明位置:/usr/share/doc/pam-0.99.6.2/txts

模組用途:限制使用者存取

模組形式:auth,

範例:

auth required pam_listfile.so oneer=succeed item=user sense=allow file=/etc/special

當加入此項於PAM時,任何列名於/etc/special中的使用者,會無法存取。

例如在 /etc/pam.d/vsftpd中的設定便會檢查 /etc/vsftpd/ftpuser中所列的使用者,並限制列名其中的使用者其使用權。

[root@server1 pam.d]# cat vsftpd

#%PAM-1.0

session optional pam_keyinit.so force revoke

auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed

auth required pam_shells.so

auth include system-auth

account include system-auth

session include system-auth

session required pam_loginuid.so


實際範例 – tally.so模組 (追蹤錯誤的登入行為)

首先我們要了解登入時所帶入的PAM模組的位置,/etc/pam.d/login再其第一行中定義了root的登入僅能藉由secure tty/etc/securetty)中,而第二行中定義了一般user在登入時的身分驗證行為,故在以下的實際操作中利用在system-auth中加入tally.so模組來追蹤使用者錯誤的登入行為。

# cd /etc/pam.d

# vi /etc/pam.d/system-auth

#%PAM-1.0

# This file is auto-generated.

# User changes will be destroyed the next time authconfig is run.

auth required pam_tally.so no_magic_root 加入

auth required pam_env.so

auth sufficient pam_unix.so nullok try_first_pass

auth requisite pam_succeed_if.so uid >= 500 quiet

auth required pam_deny.so

account required pam_unix.so

account sufficient pam_succeed_if.so uid < 500 quiet

account required pam_permit.so

password requisite pam_cracklib.so try_first_pass retry=3

password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok

password required pam_deny.so

session optional pam_keyinit.so revoke

session required pam_limits.so

session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid

session required pam_unix.so

存檔之後進行驗證:

利用其他的tty以一般user進行登入(以下以student做介紹),並故意輸入錯誤的密碼直到出現”Permission denied (publickey,gssapi-with-mic,password).”再進入系統輸入faillog –u student.

[root@server1 pam.d]# faillog -u student

Login Failures Maximum Latest On

student 6 0 01/12/08 09:47:49 +0800 192.168.1.1


2008年1月11日 星期五

用戶建立與預設家目錄中的檔案

家目錄中預設檔案的用途,以umask為例,一般我們預設umask的值為0022,亦即我們所建立的目錄權限為755,而檔案權限為644,當我們要讓相同group內的使用者可以共享檔案(g=rw)時,便可以如此做:


echo “umask 0002” >> /etc/skel/.bashrc


利用for loop快速建立使用者

實作範例:A system with user Joshua and alex in the sales group; dax and byran in the hr group; zak and ed in the web group, and manager in the sales, hr, and web groups.

#for group in sales hr web

>do

>groupadd $group

>done


#for user in Joshua alex dax byran zak ed manager

>do

>useradd $user

>done


#usermod –G sales,hr,web manager

2007年12月24日 星期一

Service: Apache - User's Personal web site


基礎需求:
帳號設定篇,套件安裝篇,apache基本操作篇

環境設定:
rpm -q httpd mod_ssl
若無相關套件請參照套件安裝篇: Utility: rpm + yum
service iptables stop

1. 在網頁空間設定上首要注意資料夾權限與SElinux設定在本次實做中以分享/home/alex為例:

useradd alex

cd /home/alex

mkdir public_html

chmod 701 /home/alex

chmod 701 /home/alex/public_html

cd /home/alex/public_html

cat >> index.html
<b> Welcome2Alex's Web Site</b>
ctrl-D

restorecon -R -v public_html

2.修改 /etc/httpd/conf/httpd.conf 約在338行開始處尋找以下字串

#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid. This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
# See also: http://httpd.apache.org/docs/misc/FAQ.html#forbidden
#
<IfModule mod_userdir.c>
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
#UserDir disable

#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disable" line above, and uncomment
# the following line instead:
#
UserDir public_html

</IfModule>

#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
# AllowOverride AuthConfig
# AuthType Basic
# AuthName "Passwd Protected Test"
# AuthUserFile /etc/httpd/.htpasswd
# require valid-user

# <Limit GET POST OPTIONS>
# Order allow,deny
# Allow from all
# </Limit>
# <LimitExcept GET POST OPTIONS>
# Order deny,allow
# Deny from all
# </LimitExcept>
</Directory>

設定值解說
  • 將UserDir disable設定改為 #UserDir disable並改為UserDir public_html,便是將預設的個人網頁空間設定為/home/*/public/html
  • 設定密碼保護
# AllowOverride AuthConfig
# AuthType Basic
# AuthName "Passwd Protected Test"
# AuthUserFile /etc/httpd/.htpasswd
# require valid-user

將以上字串的#字號拿掉後在加入以下的指令:

htpasswd -cm /etc/httpd/.htpasswd alex

chmod 640 /etc/httpd/.htpasswd

在進入網頁時便會要求輸入帳號密碼,即User based的保護機制,如下圖所示:

links http://server1/~alex

3. 檢查設定檔與執行

請執行以下指令

httpd -t

apachectl restart

4. 測試網頁

links http://ip-web service host/~alex

2007年12月5日 星期三

VNCServer 遠端桌面管理(IE Exporler控制遠端Linux主機)

前言:

在以下的裝備中,我們安裝一台windows XP主機,而另一台為Linux red hat 7.2的主機,我們將使用windows XP主機操控Linux主機的桌面。

  1. 套件安裝

    1. 下載所需套件

www.realvnc.com

    1. 安裝

在以下的安裝中,分別對windows端以及Linux端作個別的介紹。

Linux

      1. 程式解壓縮,以我下載的vnc-4_1_2-x86_linux[1].tar為例,進入檔案下載的目錄後,輸入:

tar zxvf vnc-4_1_2-x86_linux[1].tar

      1. 主程式及man page安裝

./vncinstall /usr/local/bin /usr/local/man

      1. Java VNCViewer的安裝

mkdir –p /usr/local/vnc/classes

cp java/* /usr/local/vnc/classes

Windows1

雙擊兩下即可安裝。

Linux Server

啟動VNCServer

mkdir ~/.vnc

vncpasswd

vncserver


防火牆設定

iptables –I INPUT –s 192.68.1.0/24 –p tcp –dport 5801 –j ACCEPT

iptables –I INPUT –s 192.68.1.0/24 –p tcp –dport 5901 –j ACCEPT

iptables –I INPUT –s 192.68.1.0/24 –p tcp –dport 6001 –j ACCEPT


Windows

IE Explorler中輸入位置 http://192.168.1.3:5801


驗證的畫面

登入成功摟。

1 Windows端還需要java環境才可以利用VNC進行遠端桌面管理。

2007年8月18日 星期六

20070819_七夕情人節


親愛的盈如:今天是我們兩個人的日子,對我的寶貝我有些話想要和你說,寶寶雖然我常惹你生氣,氣到跳腳,但我總是知道你總是不會離開我,而且會好好的讓我跟我溝通,或許我們倆的認知上有時會有所差別,但是我永遠都知道你對我是最好的,總是會想如何過著浪漫的一天,有了你我的生活真的變的多采多姿,永遠有不一樣的刺激,像是可以到Bali island去玩,瘋狂的購物,和你在一起雖然有時候你的吵吵鬧鬧很煩,但也帶給我的生活不少的新鮮感,也許我有時候很堅持我的意見,你也是很堅持,但你到了心平氣和後總是會想著要怎麼好好過,看著又是一年的七夕,象徵我們的愛情又過了一年,回想著這一年中發生了好多事,像是我去畢業了去當兵或是到永光去上班,你都是我最大的支柱,我們也去玩過好多的地方呀,但你好像永遠都不滿足,你讓我在工作時沒有後顧之憂,我總是希望我們的愛情能有所成長,希望寶寶不要再生悶氣了,有心是可以和我好好的溝通,我也不想讓你生氣,所以讓我們過個快快樂樂的情人節吧,這張相片雖然有點歷史,但也很值得我們紀念唷,這是我們的第一張大頭貼,最後還是要跟你說,Happy Valentine's Day, I love you。From. Chih-Kang Chang 2007/8/19