当前位置:   article > 正文

Ubuntu16.04下ssh和samba服务器安装与配置_简述使用openssh和samba的服务安装配置过程

简述使用openssh和samba的服务安装配置过程

本人安装的是Ubuntu16.04,因为平时需要Linux环境开发。方便自己在windows与Ubuntu自由操作与拷贝文件需要安装ssh与samba。

1. 如何安装配置ssh

安装openssh-server

  1. bspserver@bspserver-Hinge-tech:~$ sudo apt-get install openssh-server
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following additional packages will be installed:
  6. ncurses-term openssh-sftp-server ssh-import-id
  7. Suggested packages:
  8. ssh-askpass rssh molly-guard monkeysphere
  9. The following NEW packages will be installed:
  10. ncurses-term openssh-server openssh-sftp-server ssh-import-id
  11. 0 upgraded, 4 newly installed, 0 to remove and 184 not upgraded.
  12. Need to get 633 kB of archives.
  13. After this operation, 5,136 kB of additional disk space will be used.
  14. Do you want to continue? [Y/n] y
  15. Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 ncurses-term all 6.0+20160213-1ubuntu1 [249 kB]
  16. Get:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-sftp-server amd64 1:7.2p2-4ubuntu2.10 [38.8 kB]
  17. Get:3 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-server amd64 1:7.2p2-4ubuntu2.10 [335 kB]
  18. Get:4 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 ssh-import-id all 5.5-0ubuntu1 [10.2 kB]
  19. Fetched 633 kB in 3s (205 kB/s)
  20. Preconfiguring packages ...
  21. Selecting previously unselected package ncurses-term.
  22. (Reading database ... 178803 files and directories currently installed.)
  23. Preparing to unpack .../ncurses-term_6.0+20160213-1ubuntu1_all.deb ...
  24. Unpacking ncurses-term (6.0+20160213-1ubuntu1) ...
  25. Selecting previously unselected package openssh-sftp-server.
  26. Preparing to unpack .../openssh-sftp-server_1%3a7.2p2-4ubuntu2.10_amd64.deb ...
  27. Unpacking openssh-sftp-server (1:7.2p2-4ubuntu2.10) ...
  28. Selecting previously unselected package openssh-server.
  29. Preparing to unpack .../openssh-server_1%3a7.2p2-4ubuntu2.10_amd64.deb ...
  30. Unpacking openssh-server (1:7.2p2-4ubuntu2.10) ...
  31. Selecting previously unselected package ssh-import-id.
  32. Preparing to unpack .../ssh-import-id_5.5-0ubuntu1_all.deb ...
  33. Unpacking ssh-import-id (5.5-0ubuntu1) ...
  34. Processing triggers for man-db (2.7.5-1) ...
  35. Processing triggers for ureadahead (0.100.0-19.1) ...
  36. Processing triggers for systemd (229-4ubuntu21.28) ...
  37. Processing triggers for ufw (0.35-0ubuntu2) ...
  38. Setting up ncurses-term (6.0+20160213-1ubuntu1) ...
  39. Setting up openssh-sftp-server (1:7.2p2-4ubuntu2.10) ...
  40. Setting up openssh-server (1:7.2p2-4ubuntu2.10) ...
  41. Creating SSH2 RSA key; this may take some time ...
  42. 2048 SHA256:r5ORoBVuFpJMmbWDdcupxOcRLS7hYkMGqkeuVYszJ1A root@bspserver-Hinge-tech (RSA)
  43. Creating SSH2 DSA key; this may take some time ...
  44. 1024 SHA256:5B05ndimHdLblNM9FfC698ZnpYwi9FXVCBdEvFgIxVk root@bspserver-Hinge-tech (DSA)
  45. Creating SSH2 ECDSA key; this may take some time ...
  46. 256 SHA256:+YfjXUnWoqaPcWy5y+cGZy927PxdyFHrfkGDxIJZtW4 root@bspserver-Hinge-tech (ECDSA)
  47. Creating SSH2 ED25519 key; this may take some time ...
  48. 256 SHA256:6p3HM2inZ97W4ewjPV/9QY9Dtz5Ayn4YUN/typPRIpc root@bspserver-Hinge-tech (ED25519)
  49. Setting up ssh-import-id (5.5-0ubuntu1) ...
  50. Processing triggers for ureadahead (0.100.0-19.1) ...
  51. Processing triggers for systemd (229-4ubuntu21.28) ...
  52. Processing triggers for ufw (0.35-0ubuntu2) ...

安装openssh-client

  1. bspserver@bspserver-Hinge-tech:~$ sudo apt-get install openssh-client
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. openssh-client is already the newest version (1:7.2p2-4ubuntu2.10).
  6. 0 upgraded, 0 newly installed, 0 to remove and 184 not upgraded.

修改ssh配置需要密码安全访问

配置ssh客户端,去掉PasswordAuthentication yes前面的#号,保存退出。

  1. bspserver@bspserver-Hinge-tech:~$ sudo vim /etc/ssh/ssh_config
  2. # This is the ssh client system-wide configuration file. See
  3. # ssh_config(5) for more information. This file provides defaults for
  4. # users, and the values can be changed in per-user configuration files
  5. # or on the command line.
  6. # Configuration data is parsed as follows:
  7. # 1. command line options
  8. # 2. user-specific file
  9. # 3. system-wide file
  10. # Any configuration value is only changed the first time it is set.
  11. # Thus, host-specific definitions should be at the beginning of the
  12. # configuration file, and defaults at the end.
  13. # Site-wide defaults for some commonly used options. For a comprehensive
  14. # list of available options, their meanings and defaults, please see the
  15. # ssh_config(5) man page.
  16. Host *
  17. # ForwardAgent no
  18. # ForwardX11 no
  19. # ForwardX11Trusted yes
  20. # RhostsRSAAuthentication no
  21. # RSAAuthentication yes
  22. PasswordAuthentication yes
  23. # HostbasedAuthentication no
  24. # GSSAPIAuthentication no
  25. # GSSAPIDelegateCredentials no

重启ssh服务

  1. bspserver@bspserver-Hinge-tech:~$ sudo /etc/init.d/ssh restart
  2. [ ok ] Restarting ssh (via systemctl): ssh.service.
  3. bspserver@bspserver-Hinge-tech:~$

现在你可以通过Xshell的ssh登录你的Ubuntu了。

  1. Xshell for Xmanager Enterprise 5 (Build 0959)
  2. Copyright (c) 2002-2016 NetSarang Computer, Inc. All rights reserved.
  3. Type `help' to learn how to use Xshell prompt.
  4. [c:\~]$
  5. Connecting to 111.20.111.179:22...
  6. Connection established.
  7. To escape to local shell, press 'Ctrl+Alt+]'.
  8. Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.15.0-112-generic x86_64)
  9. * Documentation: https://help.ubuntu.com
  10. * Management: https://landscape.canonical.com
  11. * Support: https://ubuntu.com/advantage
  12. 193 packages can be updated.
  13. 159 updates are security updates.
  14. New release '18.04.5 LTS' available.
  15. Run 'do-release-upgrade' to upgrade to it.
  16. Last login: Fri Sep 17 13:34:37 2021 from 111.20.111.148
  17. bspserver@bspserver-Hinge-tech:~$

2. 如何安装配置samba

安装samba服务器

打开终端,在终端输入。或者我们使用Xshell,ssh登录Ubuntu主机。

  1. bspserver@bspserver-Hinge-tech:~$ sudo apt-get install samba
  2. [sudo] password for bspserver:
  3. Reading package lists... Done
  4. Building dependency tree
  5. Reading state information... Done
  6. The following additional packages will be installed:
  7. attr libaio1 libldb1 libsmbclient libwbclient0 python-crypto python-dnspython python-ldb python-samba python-tdb samba-common samba-common-bin samba-dsdb-modules samba-libs samba-vfs-modules tdb-tools
  8. Suggested packages:
  9. python-crypto-dbg python-crypto-doc bind9 bind9utils ctdb ldb-tools ntp smbldap-tools winbind heimdal-clients
  10. The following NEW packages will be installed:
  11. attr libaio1 python-crypto python-dnspython python-ldb python-samba python-tdb samba samba-common samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
  12. The following packages will be upgraded:
  13. libldb1 libsmbclient libwbclient0 samba-libs
  14. 4 upgraded, 13 newly installed, 0 to remove and 180 not upgraded.
  15. Need to get 1,770 kB/8,821 kB of archives.
  16. After this operation, 25.8 MB of additional disk space will be used.
  17. Do you want to continue? [Y/n] y
  18. Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 python-dnspython all 1.12.0-1 [85.2 kB]
  19. Get:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python-crypto amd64 2.6.1-6ubuntu0.16.04.3 [246 kB]
  20. Get:3 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 python-tdb amd64 1.3.8-2 [11.1 kB]
  21. Get:4 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 tdb-tools amd64 1.3.8-2 [21.0 kB]
  22. Get:5 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 samba amd64 2:4.3.11+dfsg-0ubuntu0.16.04.34 [903 kB]
  23. Get:6 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 attr amd64 1:2.4.47-2 [25.5 kB]
  24. Get:7 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 libaio1 amd64 0.3.110-2 [6,356 B]
  25. Get:8 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 samba-dsdb-modules amd64 2:4.3.11+dfsg-0ubuntu0.16.04.34 [216 kB]
  26. Get:9 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 samba-vfs-modules amd64 2:4.3.11+dfsg-0ubuntu0.16.04.34 [256 kB]
  27. Fetched 1,770 kB in 2s (666 kB/s)
  28. Preconfiguring packages ...
  29. ......
  30. ......
  31. Creating config file /etc/samba/smb.conf with new version
  32. Setting up samba-common-bin (2:4.3.11+dfsg-0ubuntu0.16.04.34) ...
  33. Setting up tdb-tools (1.3.8-2) ...
  34. update-alternatives: using /usr/bin/tdbbackup.tdbtools to provide /usr/bin/tdbbackup (tdbbackup) in auto mode
  35. Setting up samba (2:4.3.11+dfsg-0ubuntu0.16.04.34) ...
  36. Setting up attr (1:2.4.47-2) ...
  37. Setting up libaio1:amd64 (0.3.110-2) ...
  38. Setting up samba-dsdb-modules (2:4.3.11+dfsg-0ubuntu0.16.04.34) ...
  39. Setting up samba-vfs-modules (2:4.3.11+dfsg-0ubuntu0.16.04.34) ...
  40. Processing triggers for libc-bin (2.23-0ubuntu11.2) ...
  41. Processing triggers for ureadahead (0.100.0-19.1) ...
  42. Processing triggers for systemd (229-4ubuntu21.28) ...
  43. Processing triggers for ufw (0.35-0ubuntu2) ...
  44. bspserver@bspserver-Hinge-tech:~$

安装samba客户端

  1. bspserver@bspserver-Hinge-tech:~$ sudo apt-get install smbclient
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Suggested packages:
  6. cifs-utils heimdal-clients
  7. The following NEW packages will be installed:
  8. smbclient
  9. 0 upgraded, 1 newly installed, 0 to remove and 180 not upgraded.
  10. Need to get 311 kB of archives.
  11. After this operation, 1,505 kB of additional disk space will be used.
  12. Get:1 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 smbclient amd64 2:4.3.11+dfsg-0ubuntu0.16.04.34 [311 kB]
  13. Fetched 311 kB in 1s (208 kB/s)
  14. Selecting previously unselected package smbclient.
  15. (Reading database ... 182458 files and directories currently installed.)
  16. Preparing to unpack .../smbclient_2%3a4.3.11+dfsg-0ubuntu0.16.04.34_amd64.deb ...
  17. Unpacking smbclient (2:4.3.11+dfsg-0ubuntu0.16.04.34) ...
  18. Processing triggers for man-db (2.7.5-1) ...
  19. Setting up smbclient (2:4.3.11+dfsg-0ubuntu0.16.04.34) ...
  20. bspserver@bspserver-Hinge-tech:~$

新增用户名和密码

如果你的ubuntu还没有添加用户,则先添加一个用户,我这里添加一个bspserver用户。

sudo useradd bspserver

如果已经有用户了,则可以跳过这一步。

接着为这个新添加的用户设置密码。

在终端输入

sudo smbpasswd -a bspserver

会让你输入密码:

  1. New SMB password:
  2. Retype new SMB password:
  3. Added user bspserver.

修改配置文件

打开smb.conf配置文件,在终端输入

sudo vi /etc/samba/smb.conf

然后在文件中添加以下内容:

  1. [bspserver]
  2. browseable = yes
  3. writable = yes
  4. path = /home/bspserver
  5. public = yes
  6. guest ok = yes
  7. security = share
  8. create mask = 0777
  9. directory mask = 0777
  10. force directory mode = 0777
  11. force create mode = 0777

表示在登录Ubuntu共享目录的时候,是直接将自己的Ubuntu用户目录windows可见并可以访问。

启动samba服务

在ubuntu终端输入

sudo service smbd restart

启动samba服务。

在终端输入

sudo ifconfig

获取ubuntu主机的ip地址。

在windows上右键选择此电脑,选择映射网络驱动器。

点击完成。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/185232
推荐阅读
相关标签
  

闽ICP备14008679号