linux 安裝SSH Server + FTP Server(openssh-server + vsftp)


openssh-server (推薦. 一般ssh,ftp 都是單獨的,但是這個包含2個)

默認ubuntu 已經安裝了, ssh client ,ftp client

dpkg -l | grep ftp
dpkg -l | grep ssh

但是沒有安裝ssh-server, 所以需要安裝 sudo apt install openssh-server

我一般用bitVise,其中 包含ssh,可視化的ftp

輸入 ip:port
再輸入 帳號密碼。 就可以連接了

bitVise下載地址


linux確認sshserver是否啟動了:(或用“netstat -tlp”命令)

  ps -e | grep ssh

  如果只有ssh-agent那ssh-server還沒有啟動,需要/etc/init.d/ssh start,如果看到sshd那說明ssh-server已經啟動了。

  ssh-server配置文件位於/ etc/ssh/sshd_config,在這里可以定義SSH的服務端口,默認端口是22,你可以自己定義成其他端口號,如222。然后重啟SSH服務:

  sudo /etc/init.d/ssh resart


用psftp.exe 傳輸文件

在linux下一般用scp這個命令來通過ssh傳輸文件。

1、從服務器上下載文件
scp username@servername:/path/filename /var/www/local_dir(本地目錄)

例如scp root@192.168.0.101:/var/www/test.txt 把192.168.0.101上的/var/www/test.txt 的文件下載到/var/www/local_dir(本地目錄)

2、上傳本地文件到服務器
scp /path/filename username@servername:/path

例如scp /var/www/test.php root@192.168.0.101:/var/www/ 把本機/var/www/目錄下的test.php文件上傳到192.168.0.101這台服務器上的/var/www/目錄中

3、從服務器下載整個目錄
scp -r username@servername:/var/www/remote_dir/(遠程目錄) /var/www/local_dir(本地目錄)

例如:scp -r root@192.168.0.101:/var/www/test /var/www/

4、上傳目錄到服務器
scp -r local_dir username@servername:remote_dir
例如:scp -r test root@192.168.0.101:/var/www/ 把當前目錄下的test目錄上傳到服務器的/var/www/ 目錄

注:目標服務器要開啟寫入權限。

vsftpd

https://help.ubuntu.com/lts/serverguide/ftp-server.html

FTP 服務器

File Transfer Protocol (FTP) is a TCP protocol for downloading files between computers. In the past, it has also been used for uploading but, as that method does not use encryption, user credentials as well as data transferred in the clear and are easily intercepted. So if you are here looking for a way to upload and download files securely, see the section on OpenSSH in 遠程管理 instead. 

sudo apt install vsftpd

http://www.linuxidc.com/Linux/2016-09/135634.htm
http://www.cnblogs.com/swbzmx/p/5848257.html

1.sudo apt-get update

2.sudo apt-get install vsftpd ,執行完該步驟,vsftpd服務已經安裝

3.創建ftp用戶

a,創建用戶目錄 sudo mkdir /home/uftp

b,創建用戶 sudo useradd -d /home/uftp -s /bin/bash uftp

c,修改密碼 sudo passwd uftp

4,修改ftp的配置文件 /etc/vsftpd.conf

a,向文件中添加

userlist_deny=NO

userlist_enable=YES

userlist_file=/etc/allowed_users

seccomp_sandbox=NO

使文件中的"local_enable=YES"-->保存。

b,新建/etc/allowed_users文件

輸入"sudo gedit /etc/allowed_users"-->回車-->輸入uftp-->保存

c,使用gedit查看/etc/ftpusers文件中的內容

打開"終端窗口",輸入"sudo gedit /etc/ftpusers"-->回車-->打開這個文件后,看一看有沒有uftp這個用戶名,如果沒有,就直接退出。如果有就刪除uftp,因為這個文件中記錄的是不能訪問FTP服務器的用戶清單。

d,如果要更改默認下載目錄,修改/etc/vsftpd/vsftpd.conf,加入如下三行:
local_root=/

local_root表示使用本地用戶登錄到ftp時的默認目錄

----------------------------------------------

5.注意相關目錄權限

錯誤:550 Permission denied

原因:vsftp默認配置不允許上傳文件。

解決:修改/etc/vsftpd.conf

將“write_enable=YES”前面的#取消。

重啟vsftp服務器。

6.修改上傳文件的權限

默認為-rw---------

進行如下設置后:

local_umask=022

變為:-rw-r--r--

7.修改ftp編碼

使用utf8

utf8_filesystem=YES


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM