Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build FTP Server with Shell script

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to build a FTP server with Shell scripts". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

All kinds of knowledge points are written in the notes.

All you need is sudo $PATH/ftpsetup.sh. By default, log in with test/test as the user name and password. The root directory after login is read-only, and the subdirectory writable is writable.

Test ok on Ubuntu 13 and Linux Mint 15.

The code is as follows:

#! / bin/bash

# by liuhx 2013-Nov-04.

# set up the script for the ftp environment. The root directory of ftp is read-only, and the writable directory under it is writable

# you can customize the following four items

# ftp user name

UserName= "test"

# ftp password

Password= "test"

# ftp root directory, do not add / at the end

Ftp_dir= "$HOME/ftp"

# the directory name of the writable directory

Writable= "writable"

# if no sudo is added, prompt for an error and exit

If ["x$ (id-u)"! = x0]; then

Echo "Error: please run this script with 'sudo'."

Exit 1

Fi

# Core tool, vsftpd. -y is to answer yes to all prompts

Sudo apt-get-y install vsftpd

# db-util is a tool used to generate a user list database

Sudo apt-get-y install db-util

# refer to https://help.ubuntu.com/community/vsftpd#The_workshop for the following steps

# create a database of usernames and passwords, and record usernames in odd numbers and passwords in even numbers

Cd / tmp

Printf "$userName\ n$password\ n" > vusers.txt

Db_load-T-t hash-f vusers.txt vsftpd-virtual-user.db

Sudo cp-f vsftpd-virtual-user.db / etc/

Cd / etc

Chmod 600 vsftpd-virtual-user.db

If [!-e vsftpd.conf.old]; then

Sudo cp-f vsftpd.conf vsftpd.conf.old

Fi

# create a PAM file. Here-document of bash, and directly output these contents to overwrite the original file.

(sudo cat vsftpd.conf

# Virtual users need to be mapped as local users and set as themselves to avoid permission problems, but also make themselves unwritable to the ftp root directory

Sudo echo "guest_username=$owner" > > vsftpd.conf

# set that each virtual user can only browse its root and subdirectory (otherwise you can access the disk root directory)

# this will require the root directory to be unwritable, so create a subdirectory of writable

Mkdir "$ftp_dir"

Mkdir "$ftp_dir/$writable"

Sudo chmod Amurw "$ftp_dir"

Sudo chown-R $owner:$owner $ftp_dir

Sudo / etc/init.d/vsftpd restart

This is the end of the content of "how to build a FTP server with Shell script". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report