Advertisement
scriptz-team

[SSH] Setup FTP Server step by step in CentOS 6.x

Aug 21st, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.96 KB | None | 0 0
  1. _____ _____ _ _____ _____ _____ _____ _____ _____
  2. ___| | __ |_| _ |_ _|___ ___|_ _| __| _ | |
  3. |_ -| --| -| | __| | | |- _|___| | | | __| | | | |
  4. |___|_____|__|__|_|__| |_| |___| |_| |_____|__|__|_|_|_|
  5. |s C R i P T z - T E A M . i N F O|----------------------------
  6.  
  7. - iNfO -
  8.  
  9. [SSH] Setup FTP Server step by step in CentOS 6.x
  10.  
  11. - NOtIcE -
  12.  
  13. Install FTP in CentOS 6.3:
  14. This tutorial shows you how to install and configure FTP server in CentOS 6.3. Though the steps provided here are tested in CentOS 6.3, it should work on RHEL 6.x(x stands for version) and Scientific Linux 6.x too. In this tutorial my ftp server ip and hostname are 192.168.1.200 and mainserver.ostechnix.com respectively. I have already configured a local repository and i am gonna to install FTP from my local repository. For more information navigate to setup your local repoistory in CentOS 6 / RHEL 6 / Scientific Linux.
  15. Before proceed, stop the firewall.
  16.  
  17. [root@mainserver ~]# service iptables stop
  18. iptables: Flushing firewall rules: [ OK ]
  19. iptables: Setting chains to policy ACCEPT: filter [ OK ]
  20. iptables: Unloading modules: [ OK ]
  21. [root@mainserver ~]# service ip6tables stop
  22. ip6tables: Flushing firewall rules: [ OK ]
  23. ip6tables: Setting chains to policy ACCEPT: filter [ OK ]
  24. ip6tables: Unloading modules: [ OK ]
  25. [root@mainserver ~]# chkconfig iptables off
  26. [root@mainserver ~]# chkconfig ip6tables off
  27. [root@mainserver ~]#
  28.  
  29. Now let us install FTP service.
  30.  
  31. [root@mainserver ~]# yum install -y vsftpd
  32. [root@mainserver ~]# Start vsftpd service.
  33. [root@mainserver ~]# service vsftpd start
  34. Starting vsftpd for vsftpd: [ OK ]
  35. [root@mainserver ~]#
  36.  
  37. Enable vsftpd in multi-user levels.
  38.  
  39. [root@mainserver ~]# chkconfig vsftpd on
  40.  
  41. Now edit the /etc/vsftpd/vsftpd.conf file. Uncomment and edit the lines in the vsftpd.conf file which are shown in bold.
  42.  
  43. [root@mainserver ~]# cat /etc/vsftpd/vsftpd.conf
  44. # Example config file /etc/vsftpd/vsftpd.conf
  45. #
  46. # The default compiled in settings are fairly paranoid. This sample file
  47. # loosens things up a bit, to make the ftp daemon more usable.
  48. # Please see vsftpd.conf.5 for all compiled in defaults.
  49. #
  50. # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
  51. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
  52. # capabilities.
  53. #
  54. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  55. anonymous_enable=NO
  56. #
  57. # Uncomment this to allow local users to log in.
  58. local_enable=YES
  59. #
  60. # Uncomment this to enable any form of FTP write command.
  61. write_enable=YES
  62. #
  63. # Default umask for local users is 077. You may wish to change this to 022,
  64. # if your users expect that (022 is used by most other ftpd's)
  65. local_umask=022
  66. #
  67. # Uncomment this to allow the anonymous FTP user to upload files. This only
  68. # has an effect if the above global write enable is activated. Also, you will
  69. # obviously need to create a directory writable by the FTP user.
  70. #anon_upload_enable=YES
  71. #
  72. # Uncomment this if you want the anonymous FTP user to be able to create
  73. # new directories.
  74. #anon_mkdir_write_enable=YES
  75. #
  76. # Activate directory messages - messages given to remote users when they
  77. # go into a certain directory.
  78. dirmessage_enable=YES
  79. #
  80. # The target log file can be vsftpd_log_file or xferlog_file.
  81. # This depends on setting xferlog_std_format parameter
  82. xferlog_enable=YES
  83. #
  84. # Make sure PORT transfer connections originate from port 20 (ftp-data).
  85. connect_from_port_20=YES
  86. #
  87. # If you want, you can arrange for uploaded anonymous files to be owned by
  88. # a different user. Note! Using "root" for uploaded files is not
  89. # recommended!
  90. #chown_uploads=YES
  91. #chown_username=whoever
  92. #
  93. # The name of log file when xferlog_enable=YES and xferlog_std_format=YES
  94. # WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
  95. #xferlog_file=/var/log/xferlog
  96. #
  97. # Switches between logging into vsftpd_log_file and xferlog_file files.
  98. # NO writes to vsftpd_log_file, YES to xferlog_file
  99. xferlog_std_format=YES
  100. #
  101. # You may change the default value for timing out an idle session.
  102. #idle_session_timeout=600
  103. #
  104. # You may change the default value for timing out a data connection.
  105. #data_connection_timeout=120
  106. #
  107. # It is recommended that you define on your system a unique user which the
  108. # ftp server can use as a totally isolated and unprivileged user.
  109. #nopriv_user=ftpsecure
  110. #
  111. # Enable this and the server will recognise asynchronous ABOR requests. Not
  112. # recommended for security (the code is non-trivial). Not enabling it,
  113. # however, may confuse older FTP clients.
  114. #async_abor_enable=YES
  115. #
  116. # By default the server will pretend to allow ASCII mode but in fact ignore
  117. # the request. Turn on the below options to have the server actually do ASCII
  118. # mangling on files when in ASCII mode.
  119. # Beware that on some FTP servers, ASCII support allows a denial of service
  120. # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
  121. # predicted this attack and has always been safe, reporting the size of the
  122. # raw file.
  123. # ASCII mangling is a horrible feature of the protocol.
  124. ascii_upload_enable=YES
  125. ascii_download_enable=YES
  126. #
  127. # You may fully customise the login banner string:
  128. ftpd_banner=Welcome to OSTECHNIX FTP service.
  129. #
  130. # You may specify a file of disallowed anonymous e-mail addresses. Apparently
  131. # useful for combatting certain DoS attacks.
  132. #deny_email_enable=YES
  133. # (default follows)
  134. #banned_email_file=/etc/vsftpd/banned_emails
  135. #
  136. # You may specify an explicit list of local users to chroot() to their home
  137. # directory. If chroot_local_user is YES, then this list becomes a list of
  138. # users to NOT chroot().
  139. #chroot_local_user=YES
  140. #chroot_list_enable=YES
  141. # (default follows)
  142. #chroot_list_file=/etc/vsftpd/chroot_list
  143. #
  144. # You may activate the "-R" option to the builtin ls. This is disabled by
  145. # default to avoid remote users being able to cause excessive I/O on large
  146. # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
  147. # the presence of the "-R" option, so there is a strong case for enabling it.
  148. ls_recurse_enable=YES
  149. #
  150. # When "listen" directive is enabled, vsftpd runs in standalone mode and
  151. # listens on IPv4 sockets. This directive cannot be used in conjunction
  152. # with the listen_ipv6 directive.
  153. listen=YES
  154. #
  155. # This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
  156. # sockets, you must run two copies of vsftpd with two configuration files.
  157. # Make sure, that one of the listen options is commented !!
  158. #listen_ipv6=YES
  159. pam_service_name=vsftpd
  160. userlist_enable=YES
  161. tcp_wrappers=YES
  162. use_localtime=YES
  163.  
  164. Now let us restart the vsftpd service and try to connect to ftp server.
  165.  
  166. [root@mainserver ~]# service vsftpd restart
  167. Shutting down vsftpd: [ OK ]
  168. Starting vsftpd for vsftpd: [ OK ]
  169.  
  170. Connect to the ftp server.
  171. Note: Root is not allowed to connect to ftp server by default for security purpose. So lets us create a new user called ostechnix.
  172.  
  173. [root@mainserver ~]# useradd ostechnix
  174. [root@mainserver ~]# passwd ostechnix
  175. Changing password for user ostechnix.
  176. New password:
  177. BAD PASSWORD: it is based on a dictionary word
  178. Retype new password:
  179. passwd: all authentication tokens updated successfully.
  180.  
  181. Connet to FTP server using the new user ostechnix.
  182.  
  183. [root@mainserver ~]# ftp 192.168.1.200
  184. -bash: ftp: command not found
  185. [root@mainserver ~]#
  186.  
  187. Oops! ftp package is not installed. So let us install ftp package first.
  188.  
  189. [root@mainserver ~]# yum install -y ftp
  190. Loaded plugins: fastestmirror
  191. Loading mirror speeds from cached hostfile
  192. Setting up Install Process
  193. Resolving Dependencies
  194. --> Running transaction check
  195. ---> Package ftp.i686 0:0.17-51.1.el6 will be installed
  196. --> Finished Dependency Resolution
  197. Dependencies Resolved
  198. ================================================================================
  199. Package Arch Version Repository Size
  200. ================================================================================
  201. Installing:
  202. ftp i686 0.17-51.1.el6 localrepo 55 k
  203. Transaction Summary
  204. ================================================================================
  205. Install 1 Package(s)
  206. Total download size: 55 k
  207. Installed size: 91 k
  208. Downloading Packages:
  209. Running rpm_check_debug
  210. Running Transaction Test
  211. Transaction Test Succeeded
  212. Running Transaction
  213. Warning: RPMDB altered outside of yum.
  214. Installing : ftp-0.17-51.1.el6.i686 1/1
  215. Verifying : ftp-0.17-51.1.el6.i686 1/1
  216. Installed:
  217. ftp.i686 0:0.17-51.1.el6
  218. Complete!
  219. [root@mainserver ~]#
  220.  
  221. Again connect to the FTP server.
  222.  
  223. [root@mainserver ~]# ftp 192.168.1.200
  224. Connected to 192.168.1.200 (192.168.1.200).
  225. 220 Welcome to OSTECHNIX FTP service.
  226. Name (192.168.1.200:root): ostechnix
  227. 331 Please specify the password.
  228. Password:
  229. 500 OOPS: cannot change directory:/home/ostechnix
  230. Login failed.
  231. ftp>
  232.  
  233. It shows a error that the user cannot change to his $HOME directory. Type exit to return back from the ftp console and allow vsftpd daemon to change users into their $HOME directories. To do that update SELinux configuration using the command below.
  234.  
  235. [root@mainserver ~]# setsebool -P ftp_home_dir on
  236.  
  237. And finally connect to the FTP server.
  238.  
  239. [root@mainserver ~]# ftp 192.168.1.200
  240. Connected to 192.168.1.200 (192.168.1.200).
  241. 220 Welcome to OSTECHNIX FTP service.
  242. Name (192.168.1.200:root): ostechnix
  243. 331 Please specify the password.
  244. Password:
  245. 230 Login successful.
  246. Remote system type is UNIX.
  247. Using binary mode to transfer files.
  248. ftp> pwd
  249. 257 "/home/ostechnix"
  250. ftp>
  251.  
  252. Its working now. You can use your FTP server.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement