Changing Default directory on SFTP login

November 1, 2015 1.9k views
LEMP Getting Started Configuration Management

Hello
Whenever I SFTP login using FileZilla, It opens up/home/MYUSERACCOUNT
I would want to open the folder usr/share/nginx/html/ by default when I login.
(usr/share/nginx/html/ is the default directory where .html files are stored for my website)
Is there a way to do so?
Thanks :)

2 Answers

You can set the default remote directory in FileZilla and FileZilla will cd in that directory when you connect to the site. To do this, you need to go to FileZilla's Site manager and add or click on the site. Then click on the Advanced tab and you will see a field named "Default remote directory". You can enter /usr/share/nginx/html/ and click ok to save it. Now when you connect to the site, it will automatically cd into /usr/share/nginx/html/. :)

@prashantsani - Alternatively, you could simply modify the home directory for your user. You'll need to login to the CLI as root and issue the following command:

usermod -d /usr/share/nginx/html/ username

Broken down:

usermod is the user modification command

-d is the directory to set as the new home for username

... where username is the name of the user you're logging in as. This effectively removes /home/username/ as the home directory and replaces it with the one you specify above which, in this case, will be /usr/share/nginx/html/.

  • Since I dont want to change the user directory, Just log in(on ftp) on a directory, I ll go with @MDS 's answer. Thanks :D

  • This is a fantastic solution when you have an account just for SFTP. I don't know why anyone would, but yeah.

    • @victor7a7dd00de

      I actually do :-).

      SFTP users should be limited more so than users who access and run shell commands (even if you're using sudo). Given it's relatively easy to extract the owner (i.e. username) of the account owner by looking at something as simple as PHP's phpinfo() function, it's simply a more secure means of separating concerns.

      One user logs in and uses sudo, others log in to access content and code for that specific account. I personally would never mix the two.

Have another answer? Share your knowledge.