htpasswd: cannot create file on ubuntu server (Apache2 or vsFTPd)

Question

Why do I get this error: htpasswd: unable to update file /etc/vsftpd/passwd2

I am setting up my FTP server and I had trouble creating virtual users. Every time I used the htpasswd command I got this error message: julien@ju-server:~$ htpasswd -c /etc/vsftpd/passwd julien htpasswd: cannot create file /etc/vsftpd/passwd

Answer

I looked for a solution online, I thought it was a problem with apache2 modules or something, and I finally sorted it out myself. Get ready you will be amazed!

I created the folder vsftpd, I created the empty file passwd.

sudo vim /etc/vsftpd/passwd
sudo htpasswd /etc/vsftpd/passwd julien

If you get this error “htpasswd: unable to update file /etc/vsftpd/passwd2” it because you are missing the sudo.

sudo htpasswd /etc/vsftpd/passwd julien