Linux ftpshut Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux ftpshut command, which is used to gracefully shut down the FTP server. We will learn how to shut down the FTP server, prevent new connections, and allow existing connections to complete before the server is shut down. Additionally, we will cover how to schedule automatic FTP server shutdown. The lab covers practical examples and step-by-step instructions to help you master the ftpshut command.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) linux/SystemInformationandMonitoringGroup -.-> linux/crontab("`Job Scheduling`") linux/RemoteAccessandNetworkingGroup -.-> linux/ftp("`File Transferring`") linux/SystemInformationandMonitoringGroup -.-> linux/service("`Service Managing`") subgraph Lab Skills linux/crontab -.-> lab-422693{{"`Linux ftpshut Command with Practical Examples`"}} linux/ftp -.-> lab-422693{{"`Linux ftpshut Command with Practical Examples`"}} linux/service -.-> lab-422693{{"`Linux ftpshut Command with Practical Examples`"}} end

Introduction to the ftpshut Command

In this step, we will explore the ftpshut command in Linux, which is used to shut down the FTP server. The ftpshut command allows you to gracefully shut down the FTP server, preventing any new connections and allowing existing connections to complete before the server is shut down.

First, let's check if the FTP server is running on our system:

sudo systemctl status vsftpd

Example output:

● vsftpd.service - vsftpd FTP server
     Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-04-24 12:34:56 UTC; 1 day 2h ago
   Main PID: 1234 (vsftpd)
     Tasks: 1 (limit: 4915)
    Memory: 1.1M
    CGroup: /system.slice/vsftpd.service
            └─1234 /usr/sbin/vsftpd /etc/vsftpd.conf

In this example, the FTP server (vsftpd) is running on the system.

Now, let's use the ftpshut command to shut down the FTP server:

sudo ftpshut

Example output:

Shutdown time has been set to Fri Apr 28 12:34:56 2023.
No new connections will be allowed after that time.

The ftpshut command sets the shutdown time for the FTP server, which in this case is set to 4 days from now. After this time, no new connections will be allowed to the FTP server.

You can also specify a custom shutdown time using the ftpshut command:

sudo ftpshut now "Scheduled FTP server maintenance"

Example output:

Shutdown time has been set to Fri Apr 28 12:34:56 2023.
No new connections will be allowed after that time.

In this example, the FTP server will be shut down immediately, and the shutdown message "Scheduled FTP server maintenance" will be displayed to users trying to connect.

Shutting Down the FTP Server

In this step, we will learn how to shut down the FTP server using the ftpshut command.

First, let's check the status of the FTP server:

sudo systemctl status vsftpd

Example output:

● vsftpd.service - vsftpd FTP server
     Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-04-24 12:34:56 UTC; 1 day 2h ago
   Main PID: 1234 (vsftpd)
     Tasks: 1 (limit: 4915)
    Memory: 1.1M
    CGroup: /system.slice/vsftpd.service
            └─1234 /usr/sbin/vsftpd /etc/vsftpd.conf

The output shows that the FTP server is currently running.

Now, let's use the ftpshut command to shut down the FTP server:

sudo ftpshut now "Scheduled FTP server maintenance"

Example output:

Shutdown time has been set to Fri Apr 28 12:34:56 2023.
No new connections will be allowed after that time.

In this example, the FTP server will be shut down immediately, and the shutdown message "Scheduled FTP server maintenance" will be displayed to users trying to connect.

Let's verify that the FTP server has been shut down:

sudo systemctl status vsftpd

Example output:

● vsftpd.service - vsftpd FTP server
     Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Fri 2023-04-28 12:34:56 UTC; 1s ago
   Main PID: 1234 (code=exited, status=0/SUCCESS)
     Tasks: 0 (limit: 4915)
    Memory: 0B
    CGroup: /system.slice/vsftpd.service

The output shows that the FTP server is now inactive (dead), indicating that it has been successfully shut down.

Scheduling Automatic FTP Server Shutdown

In this step, we will learn how to schedule an automatic shutdown of the FTP server using the ftpshut command.

First, let's check the current status of the FTP server:

sudo systemctl status vsftpd

Example output:

● vsftpd.service - vsftpd FTP server
     Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
     Active: inactive (dead)

The output shows that the FTP server is currently inactive (dead), which means it is not running.

Now, let's schedule an automatic shutdown of the FTP server for a specific time in the future:

sudo ftpshut +1440 "Scheduled FTP server maintenance"

This command will schedule the FTP server to shut down in 1440 minutes (24 hours) from the current time, and display the message "Scheduled FTP server maintenance" to users trying to connect.

You can also schedule the shutdown for a specific date and time:

sudo ftpshut 2023-04-30 12:00 "Scheduled FTP server maintenance"

This command will schedule the FTP server to shut down on April 30, 2023, at 12:00 PM.

To verify that the automatic shutdown has been scheduled, you can check the status of the ftpshut command:

sudo ftpwho

Example output:

Shutdown time has been set to Fri Apr 28 12:34:56 2023.
No new connections will be allowed after that time.

This output shows the scheduled shutdown time for the FTP server.

Summary

In this lab, we learned how to use the ftpshut command in Linux to gracefully shut down the FTP server. The ftpshut command allows you to prevent new connections to the FTP server and allow existing connections to complete before the server is shut down. We also explored how to schedule an automatic FTP server shutdown and set a custom shutdown message.

Finally, we learned how to check the status of the FTP server and use the ftpshut command to immediately shut down the server.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like