Showing posts with label Ftp. Show all posts
Showing posts with label Ftp. Show all posts

Monday, February 20, 2012

What is the difference between FTP, FTPS and SFTP?


The most common protocols for file transfer in use today are FTP, FTPS and SFTP.  While these protocols may sound the same, there are some key differences among them.  Learning these differences can eliminate some of the common problems experienced when performing a file transfer.

FTP

The FTP (File Transfer Protocol) protocol has been around for quite some time.  The protocol itself is described in RFC 959 which was last updated in 1985.  The FTP protocol consists of two channels, the command channel and data channel.  These channels are responsible for exchanging commands and data in an FTP client session.
The command channel typically runs on server port 21 and is responsible for handling the exchange of simple commands between FTP server and client.  The USER and PASS commands used for authenticating an FTP user are examples of commands that are exchanged on the command channel.  The command channel remains open until the client sends the QUIT command to disconnect or the server forcibly disconnects the client.
The data channel runs on temporary random ports listening on the server (passive mode) or on the client (active mode) and are responsible for exchanging data in the form of file transfers and directory listings.  The LIST command used for getting a FTP server directory listing is an example of a command that opens a data channel.  Unlike the command channel which remains alive during the entire FTP session, the data channel automatically shuts down once the transfer of data is complete.

FTPS

When the FTP protocol was initially drafted security was not a primary concern.  Since then many things have changed and sending data over the Internet or any other insecure network without encryption is considered a big no-no.  In order to address this issue a set of security extensions to the original FTP protocol were proposed in RFC 2228 that protect FTP data as it travels over the network using SSL encryption.  However, just to make things more complicated, FTPS is available in two forms known as FTPS Implicit SSL and FTPS Explicit SSL.

FTPS Implicit SSL

In implicit SSL mode a required SSL session is established between client and server before any data is exchanged.  In other words, the use of SSL is implied because any attempt made by a non-SSL client would automatically be refused by the server.  Typically FTPS implicit SSL services run on port 990.

FTPS Explicit SSL

In explicit SSL mode the client can optionally switch from unencrypted mode to SSL.  This is useful in that the server can support both unencrypted FTP and encrypted FTPS sessions on a single port, typically port 21. In an explicit SSL session the client first establishes an unencrypted connection to FTP service.  Prior to sending user credentials, the client then requests that the server switch the command channel to an SSL encrypted channel using the client AUTH TLS or AUTH SSL commands.  Upon successful setup of the SSL channel the client then sends user credentials to the FTP server.  These credentials along with any other commands sent to server during the FTP session are automatically encrypted by the SSL channel. 

SFTP

SFTP is most often confused with FTPS and vice-versa.  However, unlike FTP and FTPS these protocols are not at all related.  SFTP is actually a sub-system of the SSH (Secure Shell) protocol and typically runs on port 22.  Unlike FTP/S, SFTP does not have the concept of separate command and data channels.  Instead both data and commands are transferred in specially formatted packets via a single connection.  Furthermore, unlike FTPS explicit SSL, SFTP encrypts the entire session and does not offer the ability to switch between unencrypted and encrypted mode. 

Friday, February 10, 2012

FTP Error - 500 OOPS: cannot change directory:/home/user


If you have the ftp error below with SELinux enabled, you can disable SELinux to resolve the issue.

[root@localhost ~]# ftp localhost
Connected to localhost (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (localhost:user): user
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/user
Login failed.
ftp> quit

Or you can use setsebool

su -
getsebool -a | grep ftp
setsebool -P ftp_home_dir on
getsebool -a | grep ftp

Thursday, September 15, 2011

Deploying ProFTPD: Open source FTP server software


Proftpd is a highly configurable and modular FTP daemon, whose configuration and setting up is almost similar to the web server Apache. The installation, pre and post install configuration are discussed briefly in this document.
The document requires fair knowledge of Linux and Apache webserver.

Installation.

Installation is done through ./configure script. By default, proftpd and ftpshut are installed in /usr/local/sbin/, ftpcount and ftpwho in /usr/local/bin/, the configuration file in /usr/local/etc/, and the man pages in /usr/local/man/man?/. Further, /usr/local/var/proftpd/ is used to hold the runtime scoreboard files. See the “Directory and file names” section of the ./configure –help output for the arguments to change these defaults. For instance, to place all these directories under /usr/ rather than /usr/local/, you could use:
$ ./configure --prefix=/usr
Or, to place the configuration file in /etc/ and the runtime state files in /var/proftpd/, you would use:
$ ./configure --sysconfdir=/etc --localstatedir=/var

1. Optional modules

$ ./configure --with-modules=mod_readme:mod_ldap
Some operating systems require you to use either –enable-autoshadow or –enable-shadow if you wish to use the system’s shadow password file for user authentication. Using autoshadow allows proftpd to work with either shadow or traditional password files.
If you wish to use SQL for user authentication, you must specify mod_sql and one SQL backend module, either mod_sql_mysql or mod_sql_postgres. Further, the backend module must be specified later in the module list, e.g. –with-modules=mod_sql:mod_sql_postgres. Otherwise, compilation will succeed, but SQL authentication will not work.

2. Verify correct configure operation.

Watch the output of the configure script. After configure has run, you may wish to inspect the config.h file to make sure configure didn’t make any wrong “guesses” for your platform.

3. Modify the proftpd configuration file.

This default configuration causes Proftpd to run as stand alone server.
ServerType Standalone
This configuration causes Proftpd to run as a subserver of inetd/xinetd
ServerType inetd

4. Modify the inetd/xinetd superserver configuration file.

Edit /etc/inetd.conf and then send the inetd process the HUP signal, so that it will reread the updated configuration file. On some systems there are other mechanisms to tell inetd to reread its configuration file, e.g. refresh -s inetd on AIX. Check your system documentation to see what command is appropriate.
If proftpd is to be run from inetd, find the line in /etc/inetd.conf that looks something like:
ftp stream tcp nowait root /usr/sbin/in.ftpd in.ftpd
And replace it with:
ftp stream tcp nowait root /usr/local/sbin/proftpd proftpd
Or, if the tcp wrappers package is installed on your system, you may use a line something like:
ftp stream tcp nowait root /usr/sbin/tcpd /usr/local/sbin/proftpd
If proftpd is to be run in standalone mode, you should comment out any ftp line in the /etc/inetd.conf file by inserting a # at the beginning of the line. Then signal the inetd process to reread /etc/inetd.conf.
If your system is using xinetd instead of inetd then either edit your /etc/xinetd.conf file or add a proftpd file in /etc/xinetd.d/:
service ftp
{
flags = REUSE
socket_type = stream
instances = 50
wait = no
user = root
server = /usr/sbin/proftpd
bind =
log_on_success = HOST PID
log_on_failure = HOST RECORD
}

5. Create the runtime state directory.

In order for the MaxClients and MaxClientsPerHost directives and the ftpwho and ftpcount utilities to work, proftpd must have a directory to hold its scoreboard files. The default is /usr/local/var/proftpd/, though it may have been changed in the configuration process in Step 2. The default location also can be overriden at run-time by using the ScoreboardPath directive in the proftpd.conf configuration file. Whatever diretory is used, it must exist prior to starting proftpd. If you have installed from an installation package, the installation scripts may have created the default directory. Nonetheless, if it does not already exist you must create it manually. No special permissions are needed on the directory, unless you wish to restrict who is allowed to run ftpwho and ftpcount.

Testing the Software

As of ProFTPD 1.2.0, there are no automated regression tests. However, you are encouraged to perform your own ad-hoc, manual tests.
Note that you can start proftpd directly from your shell prompt, but do remember that it must run as root for all functions to operate properly. Nonetheless, many operations can be verified without root privileges. An alternate configuration file can be specified using the -c command line switch. In the configuration file, the TCP ports may be changed from the standard default ftp (21) and ftp-data (20) ports, and an alternate passwd file may be specified. Since such a daemon will not be able to change its uid, you also must specify the user and group names to match those used to start the daemon.
To demonstrate this process, a set of example config files have been included in the sample-configurations subdirectory.
% sh sample-configurations/PFTEST.install
Sample test files successfully installed in /tmp/PFTEST.
% ./proftpd -n -d 5 -c /tmp/PFTEST/PFTEST.conf
Then, in another window, connect to the unprivileged port. PFTEST.conf uses port 2021, and PFTEST.passwd defines a user “proftpd” with password “proftpd”. Using the traditional Unix ftp client, it might look something like this:
% ftp -n -d
ftp> open 2021
ftp> user proftpd
---> USER proftpd
331 Password required for proftpd.
Password: [proftpd]
—> PASS proftpd
230 User proftpd logged in.
ftp>

Commands for showing the run time details

ftpshut : Sutting down the server at a particular time.
ftpwho,ftpcount :Shows No:of users connected
proftpd :command line interface
For more information refer man pages.

The important Proftpd Configuration Files

/etc/proftpd.conf -------------> Main conf file

/etc/proftpd/passwd.vhosts-----> Proftpd passwd file(AuthUserFile)

.ftpaccess -------------------->Overriding file, like .htaccess
The configuration is similar to httpd.conf and includes mainly three sections.
* Global environment.
* Main server configuration.
* Virtualhosts configuration.
Important configuration sections and directives are as below

Virtual-Hosts(For dedicated IPs) and Anonymous Users configuration

ExtendedLog /etc/httpd/domlogs/ftp.domain.com-ftpbytes_log READ BytesLog
TransferLog /etc/httpd/domlogs/ftp.domain.com-ftp_log
ServerName ftp.domain.com
AuthUserFile /etc/proftpd/user
MaxClients 3 "Sorry, this ftp server has reached its maximum user count (%m). Please try again later"
DirFakeGroup On ftpgroup
DirFakeUser On ftpuser
DefaultRoot ~    //The default ftp home directory(which is usually /home/user/)

AllowOverwrite on
HideGroup wheel
HideUser root

UseFtpUsers on
RequireValidShell off
User ftp
Group ftp
UserAlias anonymous ftp
DisplayLogin welcome.msg
DisplayFirstChdir .message

DenyAll

AllowAll

DenyAll

Main Server Configuration

Add this to your proftpd.conf
# This is a basic ProFTPD configuration file (rename it to
# 'proftpd.conf' for actual use. It establishes a single server
# and a single anonymous login. It assumes that you have a user/group
# "nobody" and "ftp" for normal operation.

ServerName "ProFTPD"
AuthUserFile /etc/proftpd/passwd.vhosts
LogFormat BytesLog "%b"
ServerType standalone
DeferWelcome off
DefaultServer on
DefaultRoot ~ !wheel
TransferLog /usr/local/apache/domlogs/ftpxferlog
Port 21

Saturday, June 18, 2011

Installing and configuring FTP server


A. Installing FTP server
#yum install vsftpd
#rpm -qa|grep -i vsftpd
#rpm -ql vsftpd
/etc/logrotate.d/vsftpd.log
/etc/pam.d/vsftpd
/etc/rc.d/init.d/vsftpd
/etc/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf/etc/vsftpd/vsftpd_conf_migrate.sh
/usr/sbin/vsftpd/usr/share/doc/vsftpd-2.0.5/*
/usr/share/man/man5/vsftpd.conf.5.gz
/usr/share/man/man8/vsftpd.8.gz
/var/ftp
/var/ftp/pub
B. Allow anonymous upload files
Task: allow anonymous upload file to incoming/, but could NOT download or list files from the directory.
#mkdir -p /var/ftp/incoming
#chown root.ftp /var/ftp/incoming
#chmod 730 /var/ftp/incoming
#ls -ld /var/ftp/incoming/
drwx-wx--- 2 root ftp 4096 Nov 1 03:34 /var/ftp/incoming/
Note: this results that ftp group users can ONLY upload(write) to the incoming/ folder, but could NOT list the contents of this directory or even download from it.
#vi /etc/vsftpd/vsftpd.conf
anonymous_enable=YES    # By default, YES
anon_upload_enable=YES    # Allowanonymous to upload files (by default NO)
chown_uploads=YES    # Allowed to change owner of the uploaded files from "ftp" or "anonymous" to other users
chown_username=daemon    # Change owner of the uploaded file to "daemon"
anon_umask=077    # i.e. the uploaded files with permission of 600 ( rw-------); in other means, anonymous user can NOT upload the same file twice
#service vsftpd restart
C. Testing
On FTP server:
#touch /var/ftp/incoming/server.download-incoming
#touch /var/ftp/pub/server.download-pub
On FTP client:
#touch client.upload
#ftp 192.168.75.10
Name:ftp (or anonymous)
Password: (empty)
ftp>pwd
257 "/"
* Change-rooted directory: /var/ftp
ftp>ls
drwx-wx---    2 0        50           4096 Dec 10 05:06 incoming
drwxr-xr-x    2 0        0            4096 Dec 10 05:09 pub
ftp>cd incoming
ftp>pwd
257 "/incoming"
ftp>ls
150 Here comes the directory listing.
226 Transfer done (but failed to open directory).
* Could NOT list contents of this folder.
ftp>put client.upload
150 Ok to send data.
226 File receive OK.
* Upload successfully to incoming/.
ftp>put client.upload
553 Could not create file.
* Could NOT upload the same file twice in incoming/.
ftp>get server.download-incoming
ftp>get client.upload
550 Failed to open file.
* Could NOT download files from incoming/, even the files uploaded by the anonymous user itself.
ftp>cd ..
ftp>cd pub
ftp>pwd
257 "/pub"
ftp>ls
150 Here comes the directory listing.
-rw-r--r--    1 0        0               0 Dec 10 05:19 server.download-pub
226 Directory send OK.
* Can list contents of pub/
ftp>put client.upload
553 Could not create file.
* Could NOT upload file to pub/
ftp>get server.download-pub
226 File send OK.
* Can download file from pub/

Saturday, August 14, 2010

FTP Server (VSFTPD) in Linux


VSFTPD - Very Secure File Transfer Protocol Daemon 

Features:
 1. FTPD
 2. Chroot jail
 3. anonymous and local-user auth
 4. Rate-limiting
To  Install 'vsftpd'
   yum -y install vsftpd or  rpm -ivh

To Start the server
   service vsftpd start

To verify the status of port and listening
  
netstat -ntlp | grep 21

Configure service to start when system boots into multi-user runlevel
  a. chkconfig vsftpd on
  b. chkconfig --list vsftpd

To Connect to the FTPD service:
  a. Use web browser, which defaults to anonymous
  b. Use standard FTP client, as anonymous
  c. setsebool -P ftp_home_dir=1 - permits users access to their home directory
  d. service vsftpd restart - for changes to take effect

Edit the Configuration file /etc/vsftpd/vsftpd.conf for various options. 

To Chroot jail local users & disable 'anonymous' access
  a. chroot_local_user=YES - this jails users
  b. service vsftpd restart - for changes to take effect
  c. test connectivity as 'anonymous' and 'non-anonymous' users

 To Enable IPv6 listener:
  a. listen_ipv6=YES - DO NOT USE WITH 'listen=YES(IPv4)'
  
To Restrict 'non-anonymous' user's transfer rate
   local_max_rate=1000 - restricts connections to 1000/bps (1K/s)