Selamat datang di blog saya "YENDRA84 ---- MARI MENCARI ILMU BERMANFAAT"

Jumat, 02 November 2012

Merubah Hak Akses dengan CHMOD on ubuntu

Merubah Hak Akses dengan CHMOD on ubuntu

Tidak sedikit pengguna Linux yang mengalami kebingungan karena tidak dapat mengoperasikan suatu program atau mengakses sebuah file atau direktori dikarenakan oleh hak akses yang ada pada setiap file dan direktori yang ada pada Linux.
Linux mengenal hak akses yang mengatur setiap user sehingga tiap user hanya dapat mengakses file-file atau direktori tertentu saja, hal ini digunakan untuk kepentingan keamanan sistem.
Dua perintah (program) dalam Linux yang digunakan untuk mengatur hak akses tersebut adalah chmod dan chown. Program chmod digunakan untuk mengubah hak akses suatu file, sedangkan chown digunakan untuk mengganti pemilik file tersebut.
Hak Akses dalam Linux
Sebelum melangkah lebih jauh mengenai penggunaan perintah diatas, sebelumnya perlu dijelaskan terlebih dahulu mengenai hak akses di dalam Linux.
Setiap file dan direktori yang ada dalam sistem linux memiliki tiga buah hak akses, satu untuk user itu sendiri, kemudian untuk user dalam grup yang sama dengan pemilik file dan yang terakhir untuk user lainnya.
Anda dapat melihat hak akses sebuah file dengan menggunakan perintah ls l, perhatikan contoh dibawah ini:
  • -rw-rw-r– 1 postgres postgres 41527 Jul 12 2001 summary.pdf
  • drwxrwxr-x 2 postgres postgres 4096 Sep 20 2002 Suse
  • -rw-r–r– 1 root root 4935 Aug 23 2001 T123456.log
  • -rw-r–r– 1 postgres postgres 13335 Apr 10 17:04 tchart2.java
Karakter pertama menunjukkan jenisnya, jika berisi karakter d, berarti itu adalah direktori sedangkan jika kosong berarti file. Sembilan karakter berikutnya menunjukkan hak aksesnya, dengan tiga karakter pertama menunjukkan hak akses untuk user tersebut, tiga karakter berikutnya menunjukkan hak akses untuk grup nya dan tiga karakter terakhir menunjukkan hak akses untuk user lain.
Masing-masing arti karakter tersebut dapat dilihat pada tabel berikut:
Karakter Arti Nilai
  • r (read) Hak akses untuk membaca 4
  • w (write) Hak akses untuk menulis 2
  • x (exec) Hak akses untuk menjalankan 1
Dengan mengkombinasikan nilai pada masing-masing hak akses tersebut, akan didapatkan hak akses masing-masing, perhatikan tabel berikut:
Hak Akses Nilai Arti
— 0 Tidak memiliki hak akses (tidak dapat di akses)
r– 4 Dapat dibaca dan ditulis (diedit)
rw- 6 Dapat dibaca dan ditulis (diedit)
rwx 7 Dapat dibaca, ditulis dan dieksekusi (dijalankan)
r-x 5 Dapat dibaca dan dijalankan, tetapi tidak dapat diedit
–x 1 Hanya dapat dijalankan
Berikut contoh penerapannya:
Hak Akses Nilai Arti
-rw——- 600 Pemilik memiliki hak akses baca dan tulis, sedangkan orang lain tidak memiliki hak akses apapun. Set dengan hak akses ini supaya file anda tidak dapat dibaca orang lain, biasanya digunakan untuk file-file dokumen
-rw-r–r– 644 Pemilik memiliki hak akses baca dan tulis sedangkan orang lain hanya dapat membaca saja. Gunakan hak akses ini jika anda ingin orang lain dapat membaca file anda
-rw-rw-rw- 666 Dengan hak akses ini, orang lain juga akan dapat membaca dan merubah file anda
-rwx—— 700 Pemilik dapat membaca, menulis dan menjalankan file ini, hak akses ini yang biasanya digunakan untuk menjalankan program
-rwxr-xr-x 755 Pemilik memiliki hak akses baca, tulis dan menjalankan file ini, sedangkan orang lain hanya dapat membaca dan menjalankan file tersebut
drwx—— 700 Hanya pemilik yang dapat mengakses, membaca dan menulis pada direktori tersebut. Setiap direktori harus memiliki hak akses x untuk dapat diakses
drwxr-xr-x 755 Isi direktori ini hanya dapat dirubah oleh pemilik, tetapi orang lain dapat membaca isi direktori tersebut
Menggunakan Perintah chmod
Untuk menggunakan chmod, perintahnya adalah:
# chmod hakakses namafile
misalnya:
# chmod 644 coba.txt
perintah tersebut akan mengubah hak akses file coba.txt menjadi seperti berikut:
-rw-r–r– 1 postgres postgres 41527 Jul 12 2001 coba.txt
Untuk mengganti hak akses sebuah direktori beserta dengan isinya, gunakan parameter R, dengan parameter tersebut, chmod akan dijalankan secara rekursif, misalnya seluruh file yang ada pada direktori /home/user/public_html akan dirubah hak aksesnya menjadi 755, maka perintahnya adalah sebagai berikut:
# chmod R 755 /home/user/public_html
Menggunakan Perintah chown
Perintah chown digunakan untuk mengganti pemilik sebuah file, perintah ini hanya dapat digunakan oleh user root. Perintah ini hanya dapat digunakan oleh user root. Perintahnya adalah sebagai berikut:
# chown namauser.namagrup namafile
misalnya:
# chown user.user coba.txt
perintah chown juga dapat digunakan dengan menggunakan parameter R, contohnya adalah sebagai berikut:
# chown R apache.apache /var/www/html
Perintah chattr
Seringkali secara tidak sengaja kita menghapus atau mengedit sebuah file penting, di dalam Linux tidak ada fasilitas undelete, jadi file yang telah terhapus tidak dapat dikembalikan lagi.
Perintah (program) chattr digunakan untuk melindungi sebuah file sehingga tidak akan dapat dihapus ataupun dirubah dengan perintah apapun. Perintah chattr memberikan atribut i pada file yang dilindungi, perintahnya:
# chattr +i namafile
misal:
# chattr +i penting.txt
setelah perintah tersebut dijalankan, gunakan perintah ls l untuk melihat hasilnya:
jika suatu ketika file ini akan diedit atau dihapus, terlebih dahulu atribut diatas harus dilepas, untuk melepasnya gunakan perintah berikut:
# chattr i namafile


Merubah hak akses file

Assalamualaikum wr.wb

Untuk mengubah hak akses sebuah file atau folder dapat digunakan perintah chmod, adapun rincian penjelasan perintah ini adalah sebagai berikut:

chmod
change access permissions of a file 

chmod [-fR] mode pathname ...
DESCRIPTION
chmod changes the access permissions or modes of the specified files or directories. Modes determine who can read, change or execute a file.

Options

-f  does not issue error messages concerning file access permissions, even if chmod encounters such errors.
-R changes the access permissions of all files and subdirectories under a directory if one is specified as a path name on the command line.

Modes
You can specify the mode value on the command line in either symbolic form or as an octal value.

A symbolic mode has the form
                                      [who] op permission [op permission ...]

The who value is any combination of the following:

u sets user (individual) permissions.
g sets group permissions. o sets other permissions. a sets all permissions; this is the default.

On Windows file systems, there are no group or other permissions. Therefore, they always match the individual permissions.
The op part of a symbolic mode is an operator that tells chmod to turn the permissions on or off. The possible values are:

+ turns on a permission.
- turns off a permission.
= turns on the specified permissions and turns off all others.

The permission part of a symbolic mode is any combination of the following:

r read permission. If this is off, you cannot read the file. The extended FAT and NTFS file systems ignore this permission since all files are always readable.
x Execute permission. If this is off, you cannot execute the file. The extended FAT and NTFS file systems ignore this permission since they consider all files executable.
X Execute/search permission for a directory; or execute permission for a file only when the current mode has at least one of the execute bits set. The extended FAT and NTFS file systems ignore this permission since they consider all files executable and all directories searchable.
w Write permission. If this is off, you cannot write to the file.
h Hidden attribute. Only the extended FAT and NTFS file systems recognize this attribute.
a Archive bit. Only the extended FAT and NTFS file systems recognize this attribute.
s On POSIX-compliant and UNIX systems, this stands for setuid on execution or setgid on execution permission. On Windows systems, this stands for a system file.
S On NTFS 5.0 (and up) file systems (available only on Windows NT/2000/XP/2003/Vista/7/2008 system), this is the sparse file bit. Due to limitations in the file system, once you have set this attribute, you cannot turn it off without recreating the file.
t On UNIX systems, this stands for the sticky bit. On Windows NT/2000/XP/2003/Vista/7/2008, it refers to the temporary file bit.
c Compressed file attribute.

You can specify multiple symbolic modes if you separate them with commas.
Absolute modes are octal numbers specifying the complete list of attributes for the files; you specify attributes by OR'ing together these bits.

01000000  temporary file
02000000  compressed file
04000000  sparse file
4000      Hidden file (setuid bit)
2000      System file (setgid bit)
1000      Archive bit (sticky bit)
0400      Individual read
0200      Individual write
0100      Individual execute (or list directory)
0040      Group read
0020      Group write
0010      Group execute
0004      Other read
0002      Other write
0001      Other execute

This list shows the first three bits with their meanings on Windows systems and with their meanings on UNIX and POSIX-compliant systems in parentheses. The MKS version of chmod tries to handle options in a way that parallels the POSIX approach. In the following list, each line shows a group of calls that are equivalent.
chmod 0000   chmod o=s
chmod 2000   chmod g=s   chmod =s
chmod 4000   chmod u=s   chmod =h
chmod 6000   chmod a=s   chmod ug=s   chmod =hs

Note:

=s is equivalent to 2000 on Windows systems; on UNIX and POSIX-compliant systems, =s is equivalent to 6000. MKS intends these equivalences to support commands ported to Windows from UNIX or POSIX-compliant systems. Such ported commands do not do the same thing that they do on UNIX or POSIX-compliant systems, (since Windows systems do not have the same file attributes as UNIX and POSIX), but the commands work in a consistent manner.

To get a read-only file on Windows systems, you must turn off all three write permission bits; if any of the three is on, Windows considers the file to be writable.

On Windows systems, the lc and ls commands both indicate the mode settings of files. The Windows dir command does not show these attributes, and the attrib command may only work with the read-only attribute, depending on the version of your operating system.

EXAMPLES
chmod -w nowrite   --> makes file nowrite read-only.
chmod +hrs sysfile  --> sets the hidden, read-only, and system attributes for sysfile.
chmod a=rwx file    --> turns on read, write, and execute permissions, and turns off the hidden, archive, and system attributes. This is equivalent to
chmod 0777 file

On Windows NT/2000/XP/2003/Vista/7/2008, the command
chmod -R +c d:/    --> compresses the D: drive.

DIAGNOSTICS

Possible exit status values are:
0 --> Successful completion.
1 --> Failure due to any of the following:
  • — unable to access a specified file
  • — unable to change the modes on a specified file
  • — unable to read the directory containing item to change
  • — encountered a fatal error when using the -R option
2 --> Failure due to any of the following:
  • — missing or invalid mode argument
  • — too few arguments
Messages

fatal error during "-R" option

You specified the -R option but some file or directory in the directory structure was inaccessible. This may happen because of permissions or because you have removed a removable disk unit.
read directory "name"

You do not have read permissions on the specified directory.

NOTE

chmod is provided as both an external utility and a built-in MKS KornShell utility.

ok, semoga bermanfaat.

sumber : konsultan linux dan http://www.balivisual.com/view-article-19.html
                                           http://ayikz.wordpress.com/chmod-on-ubuntu/
                                           http://farryah.blogspot.com/2011/03/merubah-hak-akses-file.html

1 komentar:

  1. saya mau tanya

    1. Jika sebuah file beratribut rw-rw-r-- apakah user group yang sama bisa
    mengubah file tersebut.
    2. Jika sebuah file beratribut rw-rw-r-- apakah user lain beda group bisa
    mengubah file tersebut.
    3. Jelaskan perintah cara mengubah group dengan menggunakan perintah
    usermod!, dengan sejumlah option, dengan bantuan man usermod
    4. Jelaskan perintah cara menambah user baru dengan bantuan man adduser
    atau useradd

    BalasHapus