All Posts All Posts

Setting Up Local Fast Deployment Environment with SFTP

September 10, 2017·
Software Engineering
·2 min read
Tecker Yu
Tecker Yu
AI Native Cloud Engineer × Part-time Investor

Preparation

First, we need to ensure that sshd, our SSH service, is running. The following example uses CentOS to demonstrate the setup process.

Required packages: openssh-clients openssh-server

Run the following command to verify that our SSH service is in active status:

$ systemctl status sshd

Getting Started

Create a new user (add sudo for non-root users):

$ adduser test
$ passwd test

Set password, update user token information, generate SSH keys locally and place the public key on the server to ensure SSH login from local to remote host is possible.

Clarify folder permissions for the new user:

$ chown root:root /../somepath/sftp
$ chmod 755 /../somepath/sftp 

Create an uploads folder under the sftp directory where all uploaded files will be stored, and set the owner to the test user:

$ chown test:test /../somepath/sftp/uploads

Set PasswordAuthentication to no and save to ensure SSH connections cannot be established with passwords, then restart the SSH service:

$ vi /etc/ssh/sshd_config
$ ...
$ systemctl restart sshd

Now try logging in locally using sftp:

sftp -i ~/.ssh/key test@ip_address

If you enter sftp successfully, it’s working!

Configuring Fast Deployment Environment with VSCode

We’re using the ftp-sync plugin here.

After installation, press F1:

Select Ftp-sync: init

You can find the ftp-sync.json file under the .vscode folder:

{
    "remotePath": "/../sftp/uploads/project",
    "host": "",	// IP address
    "username": "test",
    "password": null,	// Leave empty as we use the more secure sftp protocol for file transfer
    "port": 22,	// SSH port
    "secure": true,
    "protocol": "sftp",
    "uploadOnSave": false,
    "passive": false,
    "debug": false,
    "privateKeyPath": "/Users/user/.ssh/key",  // Local key path
    "passphrase": null,
    "ignore": [
        "\\.vscode",
        "\\.git",
        "\\.DS_Store",
        "\\node_modules",
        "\\test",
        "\\.travis.yml"		// Folders or files to ignore during upload
    ],
    "generatedFiles": {
        "uploadOnSave": false,
        "extensionsToInclude": [],
        "path": ""
    }
}

Now enjoy fast deployment to the server:

F1

Select Ftp-sync: Local To Remote

Choose full-sync to execute the upload. Success achieved!

Note: For Node.js projects, you can use pm2 to monitor file changes and automatically restart services, achieving one-click online code updates!

Reference:

https://www.digitalocean.com/community/tutorials/how-to-enable-sftp-without-shell-access-on-centos-7

Views