{"id":457,"date":"2012-11-09T18:09:00","date_gmt":"2012-11-09T16:09:00","guid":{"rendered":"http:\/\/www.notsayfam.com\/?p=457"},"modified":"2012-11-09T18:09:00","modified_gmt":"2012-11-09T16:09:00","slug":"rhel-uzerinde-verysecureftp-ornek-konfigurasyonu-ve-linux-uzerinde-ilk-script-denemem-ftpuserolusturma-scripti","status":"publish","type":"post","link":"https:\/\/www.notsayfam.com\/?p=457","title":{"rendered":"RHEL \u00fczerinde VerySecureFtp \u00f6rnek konfig\u00fcrasyonu ve Linux \u00fczerinde ilk script denemem: FtpUserOlusturma Scripti"},"content":{"rendered":"<p>Linux \u00fczerinde script yazmak biraz zor bir i\u015fmi\u015f, g\u00f6z\u00fcn\u00fc seveyim Visual Studio nun \ud83d\ude42 Bir \u00e7ok ftp kullan\u0131c\u0131s\u0131 a\u00e7mak i\u00e7in u\u011fra\u015fmak yerine san\u0131r\u0131m bu scripti yazmam ayn\u0131 hesaba geldi \ud83d\ude42 Elle mi a\u00e7sam demi\u015ftim ilk ba\u015flarda.<\/p>\n<p>Web \u00fczerinde \u00e7ok fazla bash script kayna\u011f\u0131 olmas\u0131na ra\u011fmen ben adam gibi bir site bulamad\u0131m. if ile kullan\u0131lan operat\u00f6rleri bulmam epey zaman ald\u0131.<\/p>\n<p>Linux Bash Script Notlar:<br \/>\nif operatorleri<br \/>\n|| OR<br \/>\n&amp;&amp; AND<\/p>\n<p>Renkli bir \u00e7\u0131kt\u0131 verebilmek i\u00e7in echo -e yapmak gerekiyor.<\/p>\n<p>Kaynak\u00e7a:<br \/>\n1. Very Secure Ftp Konfig\u00fcrasyonu http:\/\/www.noob2geek.com\/linux\/setup-vsftpd-debian-ubuntu\/ ve detaylar i\u00e7in google<br \/>\n2. Bash renkler i\u00e7in https:\/\/wiki.archlinux.org\/index.php\/Color_Bash_Prompt<br \/>\n<!--more--><br \/>\n<code><br \/>\n#!\/bin\/bash<br \/>\n# Mustafa KULLUKCUOGLU 24.10.2012<br \/>\n# Ftp userlarinin olusturulmasi icin yazilmistir.\"<\/code><br \/>\n<\/code><code><br \/>\ntextyesil='\\e[0;32m' # Yesil Normal yazi<br \/>\ntextkirmizi='\\e[0;31m' # Kirmizi Normal yazi<br \/>\ntextsari='\\e[0;33m' # Sari Normal yazi<br \/>\ncizgiyesil='\\e[4;32m' # Alti Cizgili Yesil<br \/>\ncizgikirmizi='\\e[4;31m' # Alti Cizgili Kirmizi<br \/>\ncizgisari='\\e[1;33m' # Alti Cizgili Sari<br \/>\ntextnormal='\\e[0m' # Normal yazi fontuna donmek icin<br \/>\n<\/code><code><br \/>\nif [ $(id -u) -eq 0 ]; then<br \/>\nif [ ${#1} -eq 0 ] || [ ${#2} -eq 0 ] || [ ${#3} -eq 0 ]; then<br \/>\necho -e \"${cizgikirmizi}Parametre sayilarinda eksik var. Lutfen asagidaki bicimde giriniz.${textnormal}\"<br \/>\necho -e \"script.sh $FTPUSER $FTPPASSWORD $DIRECTORY\"<br \/>\necho -e \"DIRECTORY parametresinin sonuna \/pub eklenerek kullanicinin\"<br \/>\necho -e \"Home klasoru bu yapilacaktir....${textnormal}\"<br \/>\necho -e \"Ornegin: ${textyesil} .\/FtpUserCreate mustafa p@ssword \/disk1\/mustafa ${textnormal}\"<br \/>\nelse<br \/>\nHOMEFOLDER=$3<br \/>\nUSER=$1<br \/>\nPASS=$2<br \/>\nif [ ! -d \"$HOMEFOLDER\" ]; then<br \/>\necho -e \"${textkirmizi}Kullanicinin home folderi: $HOMEFOLDER dizini bulunmuyor. Olusturulacak.${textnormal}\"<br \/>\nmkdir $HOMEFOLDER<br \/>\necho -e \"${textyesil} $HOMEFOLDER klasoru olusturuldu ${textnormal}\"<br \/>\nelse<br \/>\necho -e \"${textsari} $HOMEFOLDER klasoru mevcut.${textnormal}\"<br \/>\nfi<br \/>\n<\/code><code><br \/>\nHOMEPUB=$HOMEFOLDER\"\/pub\"<br \/>\nif [ ! -d \"$HOMEPUB\" ]; then<br \/>\necho -e \"${textkirmizi} Kullanicinin home pub folderi: $HOMEFOLDER bulunmuyor. Dizin olusturulacak.${textnormal}\"<br \/>\nmkdir $HOMEPUB<br \/>\necho -e \"${textyesil} $HOMEPUB klasoru olusturuldu.${textnormal}\"<br \/>\nelse<br \/>\necho -e \"${textsari} kullanicinin \"$HOMEPUB\" klasoru mevcut.${textnormal}\"<br \/>\nfi #home pub<br \/>\n<\/code><code><br \/>\n#Kullanici daha once mevcut mu bakalim<br \/>\negrep \"^$USER\" \/etc\/passwd &gt;\/dev\/null<br \/>\nif [ $? -eq 0 ]; then<br \/>\nread -p \"Mevcut kullanici silinsin mi?:(e\/h)\" cevap<br \/>\nif [ \"$cevap\" != \"e\" ]; then<br \/>\necho -e \"${textkirmizi}Kullanici silinme islemi onaylanmadigi icin cikiliyor...${textnormal}\"<br \/>\nexit 1<br \/>\nelse<br \/>\nuserdel $USER<br \/>\necho -e \"${textyesil} $USER kullanicisi silindi...${textnormal}\"<br \/>\nfi #Kullanici silmesi onayi<br \/>\nfi #Kullanici mevcutsa bolumu<br \/>\n<\/code><code><br \/>\nENCPASS=$(perl -e 'print crypt($ARGV[0], \"password\")' $PASS)<br \/>\n#echo -e $ENCPASS<br \/>\necho -e \"${textyesil} $USER kullanicisi eklenip parolasi belirleniyor...${textnormal}\"<br \/>\nuseradd -d $HOMEPUB -s \/usr\/sbin\/nologin $USER -p $ENCPASS<br \/>\necho -e \"${cizgiyesil}$USER ${textyesil} kullanicisi eklendi.. ${textnormal}\"<br \/>\nchown -R $USER $HOMEFOLDER<br \/>\necho -e \"${cizgiyesil} $USER ${textyesil} icin ${cizgiyesil} $HOMEFOLDER ${textyesil} klasoru sahipligi verildi.${textnormal}\"<br \/>\nread -p \"Kullaniciya yazma yetkisi verilecek mi?:(e\/h)\" cevap2<br \/>\nif [ \"$cevap2\" != \"h\" ]; then<br \/>\nchmod 755 $HOMEFOLDER<br \/>\nchmod 755 $HOMEPUB<br \/>\necho -e \"${cizgiyesil} $HOMEFOLDER ${textyesil} klasorune ${cizgiyesil}$USER ${textyesil}kullanicisi icin yazma yetkisi verildi.${textnormal}\"<br \/>\nelse<br \/>\nchmod 555 $HOMEFOLDER<br \/>\nchmod 555 $HOMEPUB<br \/>\necho -e \"${cizgiyesil} $HOMEFOLDER ${textyesil} klasorune ${cizgiyesil}$USER ${textyesil}kullanicisi icin sadece okuma yetkisi verildi.${textnormal}\"<br \/>\nfi #Kullanici klasor yetkilendirme<br \/>\necho -e \"${cizgiyesil} $HOMEFOLDER ${textyesil}klasoru icin yetkiler ayarlandi.${textnormal}\"<br \/>\nusermod -Gftpusers $USER<br \/>\necho -e \"$USER kullanicisi Gftpusers grubuna eklendi.\"<br \/>\necho -e $USER &gt;&gt; \/etc\/vsftpd\/vsftpd.userlist<br \/>\necho -e \"$USER kullanicisi Very Secure FTP User listesine (\/etc\/vsftpd\/vsftpd.userlist) eklendi\"<br \/>\necho -e \"${cizgiyesil}KULLANICI EKLEME ISLEMI TAMAMLANMISTIR....${textnormal}\"<br \/>\nfi #3 adet parametre kontrolu<br \/>\nelse<br \/>\necho -e \"${textkirmizi}Bu scripti calistirmak icin root yetkisine sahip olmalisiniz...${textnormal}\"<br \/>\nfi #Root Kullanici Kontrolu<br \/>\n<\/code><code><br \/>\nexit 0<br \/>\n<\/code><br \/>\n# Example config file \/etc\/vsftpd\/vsftpd.conf<br \/>\n#<br \/>\n# The default compiled in settings are fairly paranoid. This sample file<br \/>\n# loosens things up a bit, to make the ftp daemon more usable.<br \/>\n# Please see vsftpd.conf.5 for all compiled in defaults.<br \/>\n#<br \/>\n# READ THIS: This example file is NOT an exhaustive list of vsftpd options.<br \/>\n# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd&#8217;s<br \/>\n# capabilities.<br \/>\n#<br \/>\n# Allow anonymous FTP? (Beware &#8211; allowed by default if you comment this out).<br \/>\nanonymous_enable=NO<br \/>\n#<br \/>\n# Uncomment this to allow local users to log in.<br \/>\nlocal_enable=YES<br \/>\n#<br \/>\n# Uncomment this to enable any form of FTP write command.<br \/>\nwrite_enable=YES<br \/>\n#<br \/>\n# Default umask for local users is 077. You may wish to change this to 022,<br \/>\n# if your users expect that (022 is used by most other ftpd&#8217;s)<br \/>\n# umask degerini 000 yaparak tum eklenen dosyalarin<br \/>\n# yetkisinin 666 olmasini sagliyoruz<br \/>\nlocal_umask=000<br \/>\n#<br \/>\n# Uncomment this to allow the anonymous FTP user to upload files. This only<br \/>\n# has an effect if the above global write enable is activated. Also, you will<br \/>\n# obviously need to create a directory writable by the FTP user.<br \/>\n#anon_upload_enable=YES<br \/>\n#<br \/>\n# Uncomment this if you want the anonymous FTP user to be able to create<br \/>\n# new directories.<br \/>\n#anon_mkdir_write_enable=YES<br \/>\n#<br \/>\n# Activate directory messages &#8211; messages given to remote users when they<br \/>\n# go into a certain directory.<br \/>\ndirmessage_enable=YES<br \/>\n#<br \/>\n# The target log file can be vsftpd_log_file or xferlog_file.<br \/>\n# This depends on setting xferlog_std_format parameter<br \/>\nxferlog_enable=YES<br \/>\n#<br \/>\n# Make sure PORT transfer connections originate from port 20 (ftp-data).<br \/>\nconnect_from_port_20=NO<br \/>\n#<br \/>\n# If you want, you can arrange for uploaded anonymous files to be owned by<br \/>\n# a different user. Note! Using &#8220;root&#8221; for uploaded files is not<br \/>\n# recommended!<br \/>\n#chown_uploads=YES<br \/>\n#chown_username=whoever<br \/>\n#<br \/>\n# The name of log file when xferlog_enable=YES and xferlog_std_format=YES<br \/>\n# WARNING &#8211; changing this filename affects \/etc\/logrotate.d\/vsftpd.log<br \/>\n#xferlog_file=\/var\/log\/xferlog<br \/>\n#<br \/>\n# Switches between logging into vsftpd_log_file and xferlog_file files.<br \/>\n# NO writes to vsftpd_log_file, YES to xferlog_file<br \/>\nxferlog_std_format=YES<br \/>\n#<br \/>\n# You may change the default value for timing out an idle session.<br \/>\n#idle_session_timeout=600<br \/>\n#<br \/>\n# You may change the default value for timing out a data connection.<br \/>\n#data_connection_timeout=120<br \/>\n#<br \/>\n# It is recommended that you define on your system a unique user which the<br \/>\n# ftp server can use as a totally isolated and unprivileged user.<br \/>\n#nopriv_user=ftpsecure<br \/>\n#<br \/>\n# Enable this and the server will recognise asynchronous ABOR requests. Not<br \/>\n# recommended for security (the code is non-trivial). Not enabling it,<br \/>\n# however, may confuse older FTP clients.<br \/>\n#async_abor_enable=YES<br \/>\n#<br \/>\n# By default the server will pretend to allow ASCII mode but in fact ignore<br \/>\n# the request. Turn on the below options to have the server actually do ASCII<br \/>\n# mangling on files when in ASCII mode.<br \/>\n# Beware that on some FTP servers, ASCII support allows a denial of service<br \/>\n# attack (DoS) via the command &#8220;SIZE \/big\/file&#8221; in ASCII mode. vsftpd<br \/>\n# predicted this attack and has always been safe, reporting the size of the<br \/>\n# raw file.<br \/>\n# ASCII mangling is a horrible feature of the protocol.<br \/>\n#ascii_upload_enable=YES<br \/>\n#ascii_download_enable=YES<br \/>\n#<br \/>\n# You may fully customise the login banner string:<br \/>\nftpd_banner=FTP sunucusuna hosgeldiniz. Lutfen giris yapiniz.<br \/>\n#<br \/>\n# You may specify a file of disallowed anonymous e-mail addresses. Apparently<br \/>\n# useful for combatting certain DoS attacks.<br \/>\n#deny_email_enable=YES<br \/>\n# (default follows)<br \/>\n#banned_email_file=\/etc\/vsftpd\/banned_emails<br \/>\n#<br \/>\n# You may specify an explicit list of local users to chroot() to their home<br \/>\n# directory. If chroot_local_user is YES, then this list becomes a list of<br \/>\n# users to NOT chroot().<br \/>\n#chroot_list_enable=YES<br \/>\n# (default follows)<br \/>\n#chroot_list_file=\/etc\/vsftpd\/chroot_list<br \/>\n#<br \/>\n# You may activate the &#8220;-R&#8221; option to the builtin ls. This is disabled by<br \/>\n# default to avoid remote users being able to cause excessive I\/O on large<br \/>\n# sites. However, some broken FTP clients such as &#8220;ncftp&#8221; and &#8220;mirror&#8221; assume<br \/>\n# the presence of the &#8220;-R&#8221; option, so there is a strong case for enabling it.<br \/>\n#ls_recurse_enable=YES<br \/>\n#<br \/>\n# When &#8220;listen&#8221; directive is enabled, vsftpd runs in standalone mode and<br \/>\n# listens on IPv4 sockets. This directive cannot be used in conjunction<br \/>\n# with the listen_ipv6 directive.<br \/>\nlisten=YES<br \/>\n#<br \/>\n# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6<br \/>\n# sockets, you must run two copies of vsftpd whith two configuration files.<br \/>\n# Make sure, that one of the listen options is commented !!<br \/>\n#listen_ipv6=YES<\/p>\n<p>pam_service_name=vsftpd<br \/>\nuserlist_enable=YES<br \/>\ntcp_wrappers=YES<\/p>\n<p>#Giris yapmaya yetkili kullanicilar asagidaki listeye eklenmelidir<br \/>\nuserlist_file=\/etc\/vsftpd\/vsftpd.userlist<\/p>\n<p>#Kullanici listede ise erisime izin ver<br \/>\nuserlist_enable=YES<br \/>\nuserlist_deny=NO<\/p>\n<p>#Kullanici kendi klasoru haric ust klasorleri goremesin.<br \/>\nchroot_local_user=YES<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux bash Script ile very Secure Ftp kullanicisi olu\u015fturmak.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,100],"tags":[],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-linux","category-script"],"_links":{"self":[{"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=457"}],"version-history":[{"count":3,"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions\/460"}],"wp:attachment":[{"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.notsayfam.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}