Showing posts with label ftp. Show all posts
Showing posts with label ftp. Show all posts

How to add FTP user - script

- After installing FTP server -
check my HowTo post - How to install FTP server.
you want to get the next script for add your FTP users easily.

Create a new script:
# vi /usr/bin/add_ftp_user
and copy the next lines to it
#!/bin/bash
# Script to add a user to Linux system

if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi

usermod -g proftpd $username
save and run the command:
# chmod +x /usr/bin/add_ftp_user

For add a new user just run the script
# add_ftp_user
enter a user name and password
and that's it.

Enjoy


Read more >>

How to install FTP server

In every company there is a need to send big files that it's impossible to send them by mail.
The most popular way to do it is to install a FTP server.
My favorite FTP package is ProFTPD .


Installation

add user proftpd
# useradd proftpd

download proftpd-1.3.2 from here:


After download the tar file, run:
# tar -zxvf proftpd-1.3.2.tar.gz
# cd proftod-1.3.2
# ./configure --prefix=/usr --sysconfdir=/etc \ --localstatedir=/var/run &&
# make
# make install

Configuration

edit the configuration file
# vi /etc/proftpd.conf

copy/paste the next configuration to your proftpd.conf
ServerName                      "ProFTPD Default Installation"
ServerType                      standalone
DefaultServer                   on
RequireValidShell               off
Port                            21
PassivePorts                    60150 60200
UseReverseDNS                   off
IdentLookups                    off
ServerIdent                     on "Welcome to FTP Server"

AuthPAM                         on

Umask           022

SystemLog       /var/log/proftpd.log

MaxInstances    30

# Set the user and group under which the server will run.
User            proftpd
Group           proftpd

# Added this line to chroot users in their home dirs
#DefaultRoot     /var/www/html
DefaultRoot     ~

# Normally, we want files to be overwriteable.

AllowOverwrite          on


# A basic anonymous configuration, with no upload directories.
#
#User                    ftp
#Group                   ftp

# We want clients to be able to login with "anonymous" as well as "ftp".
#UserAlias               anonymous ftp

# Limit the maximum number of anonymous logins.
#MaxClients              10

# We want 'welcome.msg' displayed at login, and '.message' displayed
# in each newly chdired directory.
#DisplayLogin            welcome.msg
#DisplayChdir            .message

# Limit WRITE everywhere in the anonymous chroot.
#
#DenyAll
#
#
Create a file /etc/pam.d/ftp with the following content
(otherwise you will not be able to log in with system users using FTP):
# vi /etc/pam.d/ftp
#%PAM-1.0
auth    required        pam_unix.so     nullok
account required        pam_unix.so
session required        pam_unix.so

Extras

IF you useing IPTABLE add the lines to you iptable
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 60150:60200 -j ACCEPT
-A OUTPUT -p tcp --dport 22 -j REJECT
IF you want to Deny from FTP users access to the server via ssh run:
# vi /etc/ssh/sshd_config
and copy the next line to the end of the file
#FTP Group Block ssh Access
DenyGroups proftpd
Read more >>

How to use ftp in a shell script

If you want to send a file to FTP server for backup or for any other reason,
create new script file with your favorite editor
# vi /usr/bin/ftp_put.sh
and copy the next lines to it

#!/bin/sh
HOST='ftp server'
USER='user name'
PASSWD='password'
FILE='$1'

ftp -n $HOST
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

change the "ftp server", "user name" and "password" to your needs.
after saving the file, run the next command
# chmod +x /usr/bin/ftp_put.sh

That's it
run this command to send file to your ftp server
# ftp_put.sh /any/file/you/want


Read more >>