Search Suggest

Mount path sshfs (ssh)

ต้องการ Map drive file จากเครื่อง Server มาที่เครื่องตนเองผ่านทาง ssh เพื่อความปลอดภัย

วิธีการ

1. บนเครื่อง Server ต้องติดตั้ง package ต่อไปนี้
   1.1 CentOS
yum -y install fuse-sshfs

   1.2 Debian
apt-get install openssh-server

2. สำหรับเครื่อง Client ที่จะ sshfs เข้าไป ต้องติดตั้ง Package ต่อไปนี้

   2.1 CentOS
yum -y install fuse-sshfs

   2.2 Ubuntu
apt-get install sshfs

3. ที่เครื่อง Client สร้าง Folder ขึ้นมาเพื่อ Map drive

#mkdir /home/user/Downloads

4. สำหรับ Ubuntu เจอปัญหาว่า Map network แล้ว user ไม่สามารถเข้าไปใช้งาน Drive ได้เนื่องจากติดสิทธิ์ Root วิธีแก้ปัญหาคือ
   4.1 แก้ไขไฟล์ /etc/fuse.conf
user_allow_other --> เปิดใช้งาน
   4.2 แก้ไข /etc/modules
fuse --> เพ่ิมเข้าไปบรรทัดล่างสุด
   4.3 ต้อง Restart เครื่องก่อนถึงจะใช้งาน แต่สามารถรันคำส่ง modprobe fuse เพื่อใช้ทดสอบใช้งานได้
#modprobe fuse

Ref.
lylebackenroth

5. การรันคำสั่ง Mount sshfs
   5.1 กรณีต้องการใส่ Password

sshfs user@192.168.0.101:/home/admin/Downloads /home/user/Downloads -p 55xxx -o uid=1000 -o gid=1000 -o allow_other

คำอธิบาย

user= user ที่อยู่เครื่อง Server
@192.168.0.101 คือไอพีเครื่อง Server
:/home/admin/Downloads คือ Path บนเครื่อง Server
/home/user/Downloads คือ Path บนเครื่อง Client (อ้างอิงข้อ 3.)
-p = port ssh เดิมเป็น 22 แต่ server มีการปรับไปใช้ port อื่น เช่น 55xxx
-o uid= user id ของ user local (/etc/passwd)
-o gid= group id ของ user local (/etc/group)
-o allow_other --> เป็นการยอมให้ user local มีสิทธิ์ RW share file ได้ อ้างอิงข้อ 4.1

   5.2 กรณีไม่ต้องการใส่ Password

echo passwords | sshfs user@192.168.0.101:/home/admin/Downloads /home/user/Downloads -p 55xxx -o uid=1000 -o gid=1000 -o allow_other -o password_stdin

คำอธิบายเพิ่มเติม

echo passwords | --> เป็นการใส่ password ที่ใช้ Login ssh
-o password_stdin --> เป็นการอ่านค่า password จาก stdin

Ref.
darklaunch





Đăng nhận xét