文章目录

  • 文档配套视频讲解链接地址
  • **第16章 常用服务搭建**
    • **16.1 TFTP服务器搭建**
    • **16.2 Samba服务搭建**
    • **16.3 SSH服务搭建**
    • 16.4 xshell登录ubuntu
    • 16.5 VSCode通过SSH登录ubuntu
    • 16.6 "Bad owner or permissions on C:\\Users\\\##/.ssh"
    • 16.7 SSH免密登录
    • 16.8 github和gitee的使用
    • 16.9 https模式下使用vscode+ubuntu克隆仓库并上传代码
    • 16.10 SSH模式来实现Gitee的密码提交代码

文档配套视频讲解链接地址

  1. 腾讯课堂视频链接地址 : 63_常用服务_TFTP服务1
  2. 腾讯课堂视频链接地址 : 64_常用服务_Samba服务2
  3. 腾讯课堂视频链接地址 : 65_常用服务_SSH服务3
  4. 腾讯课堂视频链接地址 : 66_常用服务_VSCode+SSH4
  5. 腾讯课堂视频链接地址 : 67_常用服务_SSH免密登录5
  6. 腾讯课堂视频链接地址 : 68_常用服务_VSCode问题处理6
  7. 腾讯课堂视频链接地址 : 69_常用服务_github与gitee7

第16章 常用服务搭建

16.1 TFTP服务器搭建

  1. TFTP(Trial File Transfer Protocol)是一种网络协议,主要用于文件的传输。在嵌入式交叉开发环境中被广泛使用。
  2. 查看服务(软件)是否安装
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo apt policy tftpd xinetd
tftpd:已安装:(无)候选: 0.17-18ubuntu3版本列表:0.17-18ubuntu3 500500 http://mirrors.yun-idc.com/ubuntu bionic/universe amd64 Packages
xinetd:已安装:(无)候选: 1:2.3.15.3-1版本列表:1:2.3.15.3-1 500500 http://mirrors.yun-idc.com/ubuntu bionic/universe amd64 Packages
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$
  1. 安装tftp 服务器和客户端
# tftp :下载文件的客户端
# tftpd :下载文件的服务器
# xinetd :系统后台服务
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo apt install tftpd tftp xinetd
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列【新】软件包将被安装:tftp tftpd xinetd
升级了 0 个软件包,新安装了 3 个软件包,要卸载 0 个软件包,有 15 个软件包未被升级。
需要下载 138 kB 的归档。
解压缩后会消耗 404 kB 的额外空间。
获取:1 http://mirrors.yun-idc.com/ubuntu bionic/universe amd64 tftp amd64 0.17-18ubuntu3 [16.5 kB]
获取:2 http://mirrors.yun-idc.com/ubuntu bionic/universe amd64 xinetd amd64 1:2.3.15.3-1 [108 kB]
获取:3 http://mirrors.yun-idc.com/ubuntu bionic/universe amd64 tftpd amd64 0.17-18ubuntu3 [14.3 kB]
已下载 138 kB,耗时 0秒 (487 kB/s)
正在选中未选择的软件包 tftp。
(正在读取数据库 ... 系统当前共安装有 169453 个文件和目录。)
正准备解包 .../tftp_0.17-18ubuntu3_amd64.deb  ...
正在解包 tftp (0.17-18ubuntu3) ...
正在选中未选择的软件包 xinetd。
正准备解包 .../xinetd_1%3a2.3.15.3-1_amd64.deb  ...
正在解包 xinetd (1:2.3.15.3-1) ...
正在选中未选择的软件包 tftpd。
正准备解包 .../tftpd_0.17-18ubuntu3_amd64.deb  ...
正在解包 tftpd (0.17-18ubuntu3) ...
正在设置 xinetd (1:2.3.15.3-1) ...
正在设置 tftpd (0.17-18ubuntu3) ...
Note: xinetd currently is not fully supported by update-inetd.Please consult /usr/share/doc/xinetd/README.Debian and itox(8).
正在设置 tftp (0.17-18ubuntu3) ...
正在处理用于 systemd (237-3ubuntu10.53) 的触发器 ...
正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...
正在处理用于 ureadahead (0.100.0-21) 的触发器 ...
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$
  1. 启动服务是否启动
sudo systemctl status  xinetd #查看后台服务器是否启动
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo systemctl status  tftpd
Unit tftpd.service could not be found.
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo systemctl status  xinetd
● xinetd.service - LSB: Starts or stops the xinetd daemon.Loaded: loaded (/etc/init.d/xinetd; generated)Active: active (running) since Mon 2022-09-05 08:45:43 CST; 2min 37s agoDocs: man:systemd-sysv-generator(8)Tasks: 1 (limit: 2283)CGroup: /system.slice/xinetd.service└─27702 /usr/sbin/xinetd -pidfile /run/xinetd.pid -stayalive -inetd_compat -inetd_ipv69月 05 08:45:43 ubuntu xinetd[27702]: Reading included configuration file: /etc/xinetd.d/discard [file=/etc/xinetd.d/discard] [line=14]
9月 05 08:45:43 ubuntu xinetd[27702]: Reading included configuration file: /etc/xinetd.d/discard-udp [file=/etc/xinetd.d/discard-udp] [line=25]
9月 05 08:45:43 ubuntu xinetd[27702]: Reading included configuration file: /etc/xinetd.d/echo [file=/etc/xinetd.d/echo] [line=14]
9月 05 08:45:43 ubuntu xinetd[27702]: Reading included configuration file: /etc/xinetd.d/echo-udp [file=/etc/xinetd.d/echo-udp] [line=26]
9月 05 08:45:43 ubuntu xinetd[27702]: Reading included configuration file: /etc/xinetd.d/servers [file=/etc/xinetd.d/servers] [line=14]
9月 05 08:45:43 ubuntu xinetd[27702]: Reading included configuration file: /etc/xinetd.d/services [file=/etc/xinetd.d/services] [line=13]
9月 05 08:45:43 ubuntu xinetd[27702]: Reading included configuration file: /etc/xinetd.d/time [file=/etc/xinetd.d/time] [line=13]
9月 05 08:45:43 ubuntu xinetd[27702]: Reading included configuration file: /etc/xinetd.d/time-udp [file=/etc/xinetd.d/time-udp] [line=28]
9月 05 08:45:43 ubuntu xinetd[27702]: 2.3.15.3 started with libwrap loadavg labeled-networking options compiled in.
9月 05 08:45:43 ubuntu xinetd[27702]: Started working: 0 available services
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ 
  1. 设置下载和目录
sudo vi /etc/xinetd.d/tftp # 这个文件是, 配置tftp下载的目录信息 service tftp
{socket_type        = dgram protocol           = udp wait               = yesuser               = linuxserver             = /usr/sbin/in.tftpd  # 要启动的程序server_args        = -s /var/tftpboot   # 这个就是服务器的目录 disable            = no per_source         = 11cps                = 100 2flags              = IPv4
}#server_args设置的/var/tftpboot目录是tftp服务器的目录,TFTP客户端就是从这个目录里获取文件的。
#使用命令"mkdir /var/tftpboot"建立TFTP服务器的目录。然后设置/var/tftpboot的访问权限为775.
sudo mkdir /var/tftpboot
sudo chmod 0777 /var/tftpboot# 执行过程:
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo vi /etc/xinetd.d/tftp
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ ls /var/
backups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  snap  spool  tmp
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo mkdir /var/tftpboot
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ ls /var/
backups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  snap  spool  tftpboot  tmp
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo chmod 0777 /var/tftpboot
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ ls /var/
backups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  snap  spool  tftpboot  tmp
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ ls -l /var/
总用量 52
drwxrwxrwx  2 root root     4096 9月   5 08:54 tftpboot
drwxrwxrwt  9 root root     4096 9月   5 08:45 tmp
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$
  1. 重启xinetd服务
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo systemctl restart xinetd.service
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ sudo systemctl status xinetd
● xinetd.service - LSB: Starts or stops the xinetd daemon.Loaded: loaded (/etc/init.d/xinetd; generated)Active: active (running) since Mon 2022-09-05 08:56:42 CST; 12s agoDocs: man:systemd-sysv-generator(8)Process: 29097 ExecStop=/etc/init.d/xinetd stop (code=exited, status=0/SUCCESS)Process: 29103 ExecStart=/etc/init.d/xinetd start (code=exited, status=0/SUCCESS)Tasks: 1 (limit: 2283)CGroup: /system.slice/xinetd.service└─29113 /usr/sbin/xinetd -pidfile /run/xinetd.pid -stayalive -inetd_compat -inetd_ipv69月 05 08:56:42 ubuntu xinetd[29113]: Reading included configuration file: /etc/xinetd.d/discard-udp [file=/etc/xinetd.d/discard-udp] [line=25]
9月 05 08:56:42 ubuntu xinetd[29113]: Reading included configuration file: /etc/xinetd.d/echo [file=/etc/xinetd.d/echo] [line=14]
9月 05 08:56:42 ubuntu xinetd[29113]: Reading included configuration file: /etc/xinetd.d/echo-udp [file=/etc/xinetd.d/echo-udp] [line=26]
9月 05 08:56:42 ubuntu xinetd[29113]: Reading included configuration file: /etc/xinetd.d/servers [file=/etc/xinetd.d/servers] [line=14]
9月 05 08:56:42 ubuntu xinetd[29113]: Reading included configuration file: /etc/xinetd.d/services [file=/etc/xinetd.d/services] [line=13]
9月 05 08:56:42 ubuntu xinetd[29113]: Reading included configuration file: /etc/xinetd.d/tftp [file=/etc/xinetd.d/tftp] [line=13]
9月 05 08:56:42 ubuntu xinetd[29113]: Reading included configuration file: /etc/xinetd.d/time [file=/etc/xinetd.d/time] [line=13]
9月 05 08:56:42 ubuntu xinetd[29113]: Reading included configuration file: /etc/xinetd.d/time-udp [file=/etc/xinetd.d/time-udp] [line=28]
9月 05 08:56:42 ubuntu xinetd[29113]: 2.3.15.3 started with libwrap loadavg labeled-networking options compiled in.
9月 05 08:56:42 ubuntu xinetd[29113]: Started working: 1 available service
linux@ubuntu:~/work/02-linuxbase/03-cmake/06-exam$ 
  1. 测试文件的下载
linux@ubuntu:~/work/02-linuxbase/01-shell$ cp 01-hello.sh /var/tftpboot/
cp: 无法创建普通文件'/var/tftpboot/01-hello.sh': 权限不够
linux@ubuntu:~/work/02-linuxbase/01-shell$ sudo chmod 0777 /var/tftpboot/
linux@ubuntu:~/work/02-linuxbase/01-shell$ cp 01-hello.sh /var/tftpboot/
linux@ubuntu:~/work/02-linuxbase/01-shell$ cp 02-weizhi.sh  /var/tftpboot/
linux@ubuntu:~/work/02-linuxbase/01-shell$ cp 03-huanjing.sh /var/tftpboot/
linux@ubuntu:~/work/02-linuxbase/01-shell$ ls /var/tftpboot/
01-hello.sh  02-weizhi.sh  03-huanjing.shlinux@ubuntu:~/Desktop$ tftp 192.168.1.20   # 自己计算机的ip
tftp> get 01-hello.sh    # 下载/var/tftpboot目录中的文件 , 把这些文件下载到Destktop目录下
Received 110 bytes in 0.0 seconds
tftp> get 02-weizhi.sh
Received 416 bytes in 0.0 seconds
tftp> get 03-huanjing.sh
Received 109 bytes in 0.0 seconds
tftp> q    # 退出程序
linux@ubuntu:~/Desktop$

16.2 Samba服务搭建

  1. Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。
  2. 检查samba服务是否安装
linux@ubuntu:~$ sudo apt policy samba
[sudo] linux 的密码:
samba:已安装:(无)候选: 2:4.7.6+dfsg~ubuntu-0ubuntu2.28版本列表:2:4.7.6+dfsg~ubuntu-0ubuntu2.28 500500 http://mirrors.yun-idc.com/ubuntu bionic-security/main amd64 Packages500 http://mirrors.yun-idc.com/ubuntu bionic-updates/main amd64 Packages2:4.7.6+dfsg~ubuntu-0ubuntu2 500500 http://mirrors.yun-idc.com/ubuntu bionic/main amd64 Packages
linux@ubuntu:~$
  1. 安装samba软件
linux@ubuntu:~$ sudo apt install samba
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:attr ibverbs-providers libcephfs2 libibverbs1 libnl-route-3-200 libpython-stdlib librados2 python python-crypto python-dnspython python-ldbpython-minimal python-samba python-tdb python2.7 python2.7-minimal samba-common samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
建议安装:python-doc python-tk python-crypto-doc python-gpgme python2.7-doc binfmt-support bind9 bind9utils ctdb ldb-tools ntp | chrony smbldap-tools winbindheimdal-clients
下列【新】软件包将被安装:attr ibverbs-providers libcephfs2 libibverbs1 libnl-route-3-200 libpython-stdlib librados2 python python-crypto python-dnspython python-ldbpython-minimal python-samba python-tdb python2.7 python2.7-minimal samba samba-common samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
升级了 0 个软件包,新安装了 22 个软件包,要卸载 0 个软件包,有 15 个软件包未被升级。
需要下载 9,533 kB 的归档。
解压缩后会消耗 52.8 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://mirrors.yun-idc.com/ubuntu bionic-security/main amd64 python2.7-minimal amd64 2.7.17-1~18.04ubuntu1.8 [1,289 kB]
获取:2 http://mirrors.yun-idc.com/ubuntu bionic/main amd64 python-minimal amd64 2.7.15~rc1-1 [28.1 kB]
获取:3 http://mirrors.yun-idc.com/ubuntu bionic-security/main amd64 python2.7 amd64 2.7.17-1~18.04ubuntu1.8 [248 kB]
...
获取:22 http://mirrors.yun-idc.com/ubuntu bionic-security/main amd64 samba-vfs-modules amd64 2:4.7.6+dfsg~ubuntu-0ubuntu2.28 [298 kB]
已下载 9,533 kB,耗时 1秒 (8,214 kB/s)
正在预设定软件包 ...
正在选中未选择的软件包 python2.7-minimal。
(正在读取数据库 ... 系统当前共安装有 169505 个文件和目录。)
正准备解包 .../python2.7-minimal_2.7.17-1~18.04ubuntu1.8_amd64.deb  ...
正在解包 python2.7-minimal (2.7.17-1~18.04ubuntu1.8) ...
正在选中未选择的软件包 python-minimal。
正准备解包 .../python-minimal_2.7.15~rc1-1_amd64.deb  ...
...
Samba is not being run as an AD Domain Controller, masking samba-ad-dc.service.
Please ignore the following error about deb-systemd-helper not finding samba-ad-dc.service.
Created symlink /etc/systemd/system/multi-user.target.wants/nmbd.service → /lib/systemd/system/nmbd.service.
Failed to preset unit: Unit file /etc/systemd/system/samba-ad-dc.service is masked.
/usr/bin/deb-systemd-helper: error: systemctl preset failed on samba-ad-dc.service: No such file or directory
Created symlink /etc/systemd/system/multi-user.target.wants/smbd.service → /lib/systemd/system/smbd.service.
正在处理用于 mime-support (3.60ubuntu1) 的触发器 ...
正在处理用于 ureadahead (0.100.0-21) 的触发器 ...
正在处理用于 desktop-file-utils (0.23-1ubuntu3.18.04.2) 的触发器 ...
正在处理用于 libc-bin (2.27-3ubuntu1.6) 的触发器 ...
正在处理用于 systemd (237-3ubuntu10.53) 的触发器 ...
正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...
正在处理用于 gnome-menus (3.13.3-11ubuntu1.1) 的触发器 ...
正在处理用于 ufw (0.36-0ubuntu0.18.04.2) 的触发器 ...
linux@ubuntu:~$
  1. 查看samba服务是否启动
linux@ubuntu:~$ sudo systemctl status smbd.service
● smbd.service - Samba SMB DaemonLoaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2022-09-05 10:24:58 CST; 2min 19s agoDocs: man:smbd(8)man:samba(7)man:smb.conf(5)Main PID: 31250 (smbd)Status: "smbd: ready to serve connections..."Tasks: 4 (limit: 2283)CGroup: /system.slice/smbd.service├─31250 /usr/sbin/smbd --foreground --no-process-group├─31252 /usr/sbin/smbd --foreground --no-process-group├─31253 /usr/sbin/smbd --foreground --no-process-group└─31254 /usr/sbin/smbd --foreground --no-process-group9月 05 10:24:58 ubuntu systemd[1]: Starting Samba SMB Daemon...
9月 05 10:24:58 ubuntu systemd[1]: Started Samba SMB Daemon.
linux@ubuntu:~$
  1. 配置共享目录 /etc/samba/smb.conf
sudo vi /etc/samba/smb.conf
#在文件末尾追加:
[work]   # 表示共享目录的名称 , 只是一个标号 comment = work folder  # 表述信息 browseable = yes    # 可浏览 path = /home/linux/work  #共享的路径 create mask = 0777  # 可读 , 可写 , 可执行 directory mask = 0777  # 不屏蔽权限 valid users = linux   #有效的用户 linux force user = linux   # 指定linuxforce group = linux  # 指定linux public = yes          # 不是私有的writeable = yes      # 可写 available = yes     # 有效
  1. 设置访问密码
sudo smbpasswd -a linux  // 密码 ,设置用户(liunux)的密码
#根据提示深入用户密码(登陆Samba共享目录的时候需要)。linux@ubuntu:~$ sudo vi /etc/samba/smb.conf
linux@ubuntu:~$ sudo smbpasswd -a linux
New SMB password:     # 1
Retype new SMB password:  # 1
Added user linux.
linux@ubuntu:~$
  1. 重启samba服务
sudo systemctl  restart smbd.servicelinux@ubuntu:~$ sudo systemctl restart smbd.service
linux@ubuntu:~$ sudo systemctl status smbd.service
● smbd.service - Samba SMB DaemonLoaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2022-09-05 10:35:40 CST; 8s agoDocs: man:smbd(8)man:samba(7)man:smb.conf(5)Main PID: 33097 (smbd)Status: "smbd: ready to serve connections..."Tasks: 4 (limit: 2283)CGroup: /system.slice/smbd.service├─33097 /usr/sbin/smbd --foreground --no-process-group├─33099 /usr/sbin/smbd --foreground --no-process-group├─33100 /usr/sbin/smbd --foreground --no-process-group└─33101 /usr/sbin/smbd --foreground --no-process-group9月 05 10:35:40 ubuntu systemd[1]: Starting Samba SMB Daemon...
9月 05 10:35:40 ubuntu systemd[1]: Started Samba SMB Daemon.
linux@ubuntu:~$
  1. 测试samba服务
#Ubuntu测试:
->在Ubuntu中点击文件图标 -> 其他位置 -> 底部的连接到服务器中输入服务器地址:
smb://192.168.1.20/work       # ip 是自己电脑的ip地址
然后点击右下角的Connect按钮.
此时会提示输入密码(在第6步中创建),输入密码后即可进入共享目录。
  1. window下测试samba服务
打开window的资源管理器(文件夹) -> 在地址栏输入:  \\192.168.1.20\work
-> 用户名: linux 密码: 1

点击此电脑 , 添加一个网络驱动器

  1. 知识点的补充

    使用以上配置 , 发现不能写文件夹和创建文件, 因为没有设置force user 和 force group, 才会导致权限的问题 , 重新配置如下:

[work]  comment = work folder   browseable = yes    path = /home/linux/work create mask = 0777  directory mask = 0777 valid users = linux  force user = linux   #  用户force group = linux  #  组 都这是都linux public = yes      writeable = yes    available = yes   # 重启服务linux@ubuntu:~$ sudo systemctl status smbd.service
● smbd.service - Samba SMB DaemonLoaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2022-09-05 11:13:41 CST; 6min agoDocs: man:smbd(8)man:samba(7)man:smb.conf(5)Main PID: 33423 (smbd)Status: "smbd: ready to serve connections..."Tasks: 5 (limit: 2283)CGroup: /system.slice/smbd.service├─33423 /usr/sbin/smbd --foreground --no-process-group├─33425 /usr/sbin/smbd --foreground --no-process-group├─33426 /usr/sbin/smbd --foreground --no-process-group├─33427 /usr/sbin/smbd --foreground --no-process-group└─33434 /usr/sbin/smbd --foreground --no-process-group9月 05 11:13:41 ubuntu systemd[1]: Starting Samba SMB Daemon...
9月 05 11:13:41 ubuntu systemd[1]: Started Samba SMB Daemon.
9月 05 11:14:47 ubuntu smbd[33434]: pam_unix(samba:session): session opened for user linux by (uid=0)
linux@ubuntu:~$

16.3 SSH服务搭建

  1. 什么是SSH

​ SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定;SSH 为建立在应用层基础上的安全协议。SSH 是较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。SSH最初是UNIX系统上的一个程序,后来又迅速扩展到其他操作平台。SSH在正确使用时可弥补网络中的漏洞。SSH客户端适用于多种平台。几乎所有UNIX平台—包括HP-UX、Linux、AIX、Solaris、Digital UNIX、Irix,以及其他平台,都可运行SSH。

  1. 查看系统是否安装SSH服务
linux@ubuntu:~$ sudo apt policy openssh-client openssh-server
openssh-client:已安装:1:7.6p1-4ubuntu0.7候选: 1:7.6p1-4ubuntu0.7版本列表:*** 1:7.6p1-4ubuntu0.7 500500 http://mirrors.yun-idc.com/ubuntu bionic-updates/main amd64 Packages100 /var/lib/dpkg/status1:7.6p1-4ubuntu0.5 500500 http://mirrors.yun-idc.com/ubuntu bionic-security/main amd64 Packages1:7.6p1-4 500500 http://mirrors.yun-idc.com/ubuntu bionic/main amd64 Packages
openssh-server:已安装:1:7.6p1-4ubuntu0.7候选: 1:7.6p1-4ubuntu0.7版本列表:*** 1:7.6p1-4ubuntu0.7 500500 http://mirrors.yun-idc.com/ubuntu bionic-updates/main amd64 Packages100 /var/lib/dpkg/status1:7.6p1-4ubuntu0.5 500500 http://mirrors.yun-idc.com/ubuntu bionic-security/main amd64 Packages1:7.6p1-4 500500 http://mirrors.yun-idc.com/ubuntu bionic/main amd64 Packages
linux@ubuntu:~$
  1. 安装ssh服务
sudo apt install openssh-client openssh-server
linux@ubuntu:~$ sudo apt install openssh-client openssh-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
openssh-client 已经是最新版 (1:7.6p1-4ubuntu0.7)。
openssh-server 已经是最新版 (1:7.6p1-4ubuntu0.7)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 15 个软件包未被升级。
linux@ubuntu:~$
  1. 检查ssh服务是否启动
linux@ubuntu:~$ sudo systemctl status sshd.service
● ssh.service - OpenBSD Secure Shell serverLoaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2022-08-29 09:36:30 CST; 1 weeks 0 days agoMain PID: 780 (sshd)Tasks: 1 (limit: 2283)CGroup: /system.slice/ssh.service└─780 /usr/sbin/sshd -D9月 05 10:09:17 ubuntu systemd[1]: Reloading OpenBSD Secure Shell server.
9月 05 10:09:17 ubuntu systemd[1]: Reloaded OpenBSD Secure Shell server.
9月 05 10:09:17 ubuntu sshd[780]: Received SIGHUP; restarting.
9月 05 10:09:17 ubuntu sshd[780]: Server listening on 0.0.0.0 port 22.
9月 05 10:09:17 ubuntu sshd[780]: Server listening on :: port 22.
9月 05 10:09:18 ubuntu systemd[1]: Reloading OpenBSD Secure Shell server.
9月 05 10:09:18 ubuntu sshd[780]: Received SIGHUP; restarting.
9月 05 10:09:18 ubuntu systemd[1]: Reloaded OpenBSD Secure Shell server.
9月 05 10:09:18 ubuntu sshd[780]: Server listening on 0.0.0.0 port 22.
9月 05 10:09:18 ubuntu sshd[780]: Server listening on :: port 22.
linux@ubuntu:~$ sudo systemctl status ssh
sshd.service  ssh.service   ssh.socket
linux@ubuntu:~$ sudo systemctl status ssh.service   # sshd.server 和 ssh.server 是一样的服务
● ssh.service - OpenBSD Secure Shell serverLoaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2022-08-29 09:36:30 CST; 1 weeks 0 days agoMain PID: 780 (sshd)Tasks: 1 (limit: 2283)CGroup: /system.slice/ssh.service└─780 /usr/sbin/sshd -D9月 05 10:09:17 ubuntu systemd[1]: Reloading OpenBSD Secure Shell server.
9月 05 10:09:17 ubuntu systemd[1]: Reloaded OpenBSD Secure Shell server.
9月 05 10:09:17 ubuntu sshd[780]: Received SIGHUP; restarting.
9月 05 10:09:17 ubuntu sshd[780]: Server listening on 0.0.0.0 port 22.
9月 05 10:09:17 ubuntu sshd[780]: Server listening on :: port 22.
9月 05 10:09:18 ubuntu systemd[1]: Reloading OpenBSD Secure Shell server.
9月 05 10:09:18 ubuntu sshd[780]: Received SIGHUP; restarting.
9月 05 10:09:18 ubuntu systemd[1]: Reloaded OpenBSD Secure Shell server.
9月 05 10:09:18 ubuntu sshd[780]: Server listening on 0.0.0.0 port 22.
9月 05 10:09:18 ubuntu sshd[780]: Server listening on :: port 22.
linux@ubuntu:~$
  1. 在Window下进行测试 ,运行 cmd 或者 PowerShell ,输入链接命令:
ssh linux@192.168.1.20     # ssh   用户名@ip地址    , 是自己ubuntu的ip地址PS C:\Users\sheng> ssh linux@192.168.1.20  # 在window下登录ubuntu
The authenticity of host '192.168.1.20 (192.168.1.20)' can't be established.
ECDSA key fingerprint is SHA256:g+rxrkFtBCIwTyzY4xIPvtftDh8f04+ydYM6SFGdmBI.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.1.20' (ECDSA) to the list of known hosts.
linux@192.168.1.20's password:     # 输入密码 1
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-124-generic x86_64)* Documentation:  https://help.ubuntu.com* Management:     https://landscape.canonical.com* Support:        https://ubuntu.com/advantage15 updates can be applied immediately.
14 of these updates are standard security updates.
To see these additional updates run: apt list --upgradableYour Hardware Enablement Stack (HWE) is supported until April 2023.The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.linux@ubuntu:~$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  snap  Templates  Videos  work

16.4 xshell登录ubuntu

安装软件并选择免费为家庭/学校

安装完成后, 运行软件是会弹出新建连接对话框

->在弹出的对话框中点击新建
-> 名称: ubuntu18.04协议: ssh 主机: 192.168.1.20   # ubuntu主机的ip地址 说明信息: 用户名:linux 密码  :1
-> 点击确定

选中ubuntu18.04 之后点击连接

会提示, 是否保存秘钥 ,可以保存用户名和密码 , 下一次连接时可以不输入密码, 选择接收并保存

输入用户名:linux , 选择记住用户名 , 点击确定

正产输入密码后,即可连接, 如果没有连接上 , 可以点击工具栏中的重新连接

点击重新连接后, 输入密码, 选择记住密码, 下次可以不在输入密码 , 之后点击确定。

连接成功如下:

16.5 VSCode通过SSH登录ubuntu

  1. 安装vscode的ssh插件

打开vscode软件 , 点击“扩展” , 在搜索框中输入: ssh , 之后点击安装即可。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5Jr8nuyU-1667655879391)(C:/Users/sheng/AppData/Roaming/Typora/typora-user-images/image-20220905155605455.png)]

安装成功后 , 在侧边栏会有一个 远程资源管理器, 单击如下图:

  1. 使用ssh 连接ubuntu18.04

如下图, 点击 “+” , 新建一个连接, 在弹出的输入框中输入:

ssh linux@192.168.1.20

-> 选择 C:\user\sheng\.ssh\config 文件
-> 在弹出的对话中选择 , OpenConfig 选项
-> 添加如下信息:Host ubuntu18.04-2207HostName 192.168.1.20User linuxForwardAgent yes# 使用ctrl + s 保存文件

在远程资源管理窗口中点击 刷新后, 会出现我们配置的连接信息,之后右击“ubuntu18.04-2207”

选择 “Connect to Host in Current Window” , 开始连接

平台选择: linux

密码: 1

之后按下回车键即可完成连接 , 出现如下图, 表示成功连接。

打开“资源管理器” , 选择打开文件夹 , 选择 /home/linux/work 目录, 点击确定。

之后再次输入密码: 1

选择 “是, 我信任此作者 信任文件夹并启动所有功能”

成功打开后, 如下图

开启终端: ctrl + ~ 开启终端, 再按一次关闭终端

  1. vscode 安装runner code 插件

单击扩展 , 在搜索框中输入: code , 选择Code Runner , 打开目录有, 右击代码选择 “Run Code” 即可完成运行代码

16.6 “Bad owner or permissions on C:\Users\##/.ssh”

  1. 第一种可能的解决办法
vscode 中 "Bad owner or permissions on C:\\Users\\\##/.ssh"
解决办法:
-> 文件
-> 首选项
-> 设置
-> 扩展
-> Remote-SSH
-> Remote.SSH: Config FileThe absolute file path to a custom SSH config file."C:\Users\YShengli\.ssh\config"
-> 再次连接, 以上问题即可解决
  1. 第二种可能的解决办法

在ip地址改变以后, 同样也会发生这样的问题 , 解决办法: 直接删除windonw下的known_hosts

PS C:\Users\sheng> cd .\.ssh\
PS C:\Users\sheng\.ssh> ls目录: C:\Users\sheng\.sshMode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----            22/9/5     16:05            301 config
-a----            22/9/6     08:57           2602 id_rsa
-a----            22/9/6     08:57            569 id_rsa.pub
-a----            22/9/6     09:43            877 known_hostsPS C:\Users\sheng\.ssh> rm .\known_hosts  # 也可以打开这个文件,删除指定的秘钥

再次连接一次即可。

16.7 SSH免密登录

xshell 可以自动保存秘钥, 因此可以免密登录

window下的powershell没有免密登录的功能,vscode的ssh插件也没有这个功能, 我们需要手动的生成秘钥, 来进行免密登录

  1. 在window 下 进入cmd 或则 powershell
进入目录:C:\Users\sheng\.ssh>
输入命令:ssh-keygen -t rsa
目录里面会生成两个文件: id_rsa  id_rsa.pub# 执行过程:
PS C:\Users\sheng> cd .\.ssh\
PS C:\Users\sheng\.ssh> ls目录: C:\Users\sheng\.sshMode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----            22/9/5     16:05            301 config
-a----            22/9/5     14:17            701 known_hostsPS C:\Users\sheng\.ssh> pwdPath
----
C:\Users\sheng\.sshPS C:\Users\sheng\.ssh> ssh-keygen -t rsa   # 生成密码文件
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\sheng/.ssh/id_rsa):    # 回车
Enter passphrase (empty for no passphrase):   # 回车
Enter same passphrase again:  # 回车
Your identification has been saved in C:\Users\sheng/.ssh/id_rsa.
Your public key has been saved in C:\Users\sheng/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:S/fj/sL5AKxi4bvu08kQhDnkrv03UGR+4Pmn3KN51CM sheng@YShengli
The key's randomart image is:
+---[RSA 3072]----+
|   ..o           |
|   .+ . +        |
|    .o = o       |
|   .  . =..      |
|    . .oSo+  .   |
|   o .oo +.oE o  |
|  . . +=oo *+o . |
|     o.o* ooBo   |
|     o*+ .o+o=o  |
+----[SHA256]-----+
PS C:\Users\sheng\.ssh>
PS C:\Users\sheng\.ssh> ls目录: C:\Users\sheng\.sshMode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----            22/9/5     16:05            301 config
-a----            22/9/6     08:57           2602 id_rsa
-a----            22/9/6     08:57            569 id_rsa.pub
-a----            22/9/5     14:17            701 known_hostsPS C:\Users\sheng\.ssh>
  1. 在ubuntu中也生成一个密钥
# 执行过程
linux@ubuntu:~$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  snap  Templates  Videos  work
linux@ubuntu:~$ ssh-keygen -t rsa    # 生成秘钥
Generating public/private rsa key pair.
Enter file in which to save the key (/home/linux/.ssh/id_rsa):   # 回车
Enter passphrase (empty for no passphrase):   # 回车
Enter same passphrase again:    # 回车
Your identification has been saved in /home/linux/.ssh/id_rsa.
Your public key has been saved in /home/linux/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:GDj+F21ZALB1NGuWaAm8+sNXKTfNBN1CWARa0EqOHvM linux@ubuntu
The key's randomart image is:
+---[RSA 2048]----+
|     .o.+=BB+.   |
|     ..+.*+=o .  |
|    o o==.=...   |
|   . .=+o+ o.    |
|    .o.+S +=     |
|    ... Eo= o    |
|     o. .+ .     |
|      +..        |
|       o         |
+----[SHA256]-----+
linux@ubuntu:~$ linux@ubuntu:~$ ls .ssh/     # 生成了2个文件   id_rsa  id_rsa.pub
id_rsa  id_rsa.pub
linux@ubuntu:~$
  1. 把window下生成的秘钥放到ubuntu中去, 即可实现免密登录

把window下的 C:\Users\YShengli\.ssh>id_rsa.pub 复制到ubuntu的/home/linux 目录下

linux@ubuntu:~$ ls
Desktop  Documents  Downloads  id_rsa.pub  Music  Pictures  Public  snap  Templates  Videos  work
linux@ubuntu:~$ cat id_rsa.pub >>.ssh/authorized_keys  #把id_rsa.pub 加入到信任密钥列表中去
linux@ubuntu:~$ rm id_rsa.pub   #删除id_rsa.pub
linux@ubuntu:~$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  snap  Templates  Videos  work
linux@ubuntu:~$
  1. powershell测试免密连接
PS C:\Users\sheng> ssh linux@192.168.1.20  # 测试连接命令
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-124-generic x86_64)* Documentation:  https://help.ubuntu.com* Management:     https://landscape.canonical.com* Support:        https://ubuntu.com/advantage15 updates can be applied immediately.
14 of these updates are standard security updates.
To see these additional updates run: apt list --upgradableYour Hardware Enablement Stack (HWE) is supported until April 2023.
Last login: Tue Sep  6 08:54:16 2022 from 192.168.1.103
linux@ubuntu:~$
linux@ubuntu:~$ exit  # 断开连接
注销
Connection to 192.168.1.20 closed.
PS C:\Users\sheng>
  1. vscode 测试免密连接

直接使用vscode的ssh连接ubuntu即可, 中途不需要输入密码即可ssh连接ubuntu18.04

16.8 github和gitee的使用

  1. GitHub是一个面向开源及私有软件项目的托管平台,因为只支持Git作为唯一的版本库格式进行托管,故名GitHub。

由于github国内访问速度过慢,使用很不方便, 使用国内的替代网站, 就是gitee 。

  1. Gitee是开源中国(OSChina)推出的基于Git的代码托管服务
  2. 使用gitee 来创建一个组织和仓库
-> 注册账号并登陆账号
-> 登陆成功后,点击右上角的"+"
-> 创建组织
-> 输入组织的名称 :iotemb
-> 再次点击右上角的"+"
-> 新建仓库
-> 输入: 创库名称 : emb2207
-> 根据提示 完成仓库的创建

16.9 https模式下使用vscode+ubuntu克隆仓库并上传代码

  1. ubuntu18.04 中安装git
linux@ubuntu:~$ sudo apt install git
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
git 已经是最新版 (1:2.17.1-1ubuntu0.12)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 15 个软件包未被升级。
linux@ubuntu:~$
  1. 使用git克隆代码
-> gitee中找到自己的创库
-> 选择 "克隆/下载" 选项
-> 选择 Https
-> 选择 复制
-> 即可得到仓库的地址  https://gitee.com/iotemb/emb2207.git
-> vscode 使用ssh 登录ubuntu18.04
-> vscode 中的代码管理器
-> 克隆仓库
-> 在弹出的输入框中输入仓库地址: https://gitee.com/iotemb/emb2207.git
-> 选择存放的路径, emb2207.git将来会创建一个目录,这个目录是emb2207 , 这个注意一下
-> 提示输入账号和密码账号: 18612251094密码: *********  # 自己账户的密码
-> 在提示是否打开创库时
-> 选择打开仓库
-> 把本地的代码复制到 这个目录内
-> 点击vscode中的"代码管理器"
-> 在消息输入框中输入:一般是说明信息, 哪一个用户
-> 提交
-> 即可完成本地数据上传代码托管平台

https的模式下每次都需要输入账号和密码 , 这种方式使用起来很麻烦 , 可以使用ssh的方式来实现免密登录

16.10 SSH模式来实现Gitee的密码提交代码

  1. 在ubuntu18.04 中生成密码

    请参考16.7 章节去实现

  2. 把密码保存到gitee服务器中

-> 登录gitee账号
-> 设置
-> 安全设置
-> SSH 公钥
-> 使用命令 获取ubuntu18.04中秘钥的内容
-> 把秘钥中的内容复制到下图的文本框中
-> 确定
-> 输gitee 的密码
-> 添加秘钥成功
linux@ubuntu:~$ cd .ssh/
linux@ubuntu:~/.ssh$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCn8gt9bl9rbxB7BMfTuTrVCnA5LfQLC0O9l5geFooLaPKrU3G0OIIPYy/lhxoPbryONuHlmJZr+Ur901iKLtncdwsWhQt7bhVZJsV//vsSAF4yXIy97r6nuQSie8pGWVNGQqIOs0LvNVMwlF4XBtY/hNHN4mCLf8BCvvVdHbm7fOOAqBwnnwT42lOmWg7N4QvOaflqaoGFE+c1f6K5w78cimW0uTWL9a+DD85cGCwLT+vmQP7qhJjCxyjaNgbaDDkU6/xRDH6YrG6t8Kb95ZmhRRQWZfuHUWwaoY3FMVT7jYQrISqk22J2Ghj3ZoM3yw86TEoySe8l+Sb/1zmXGeZ linux@ubuntu
linux@ubuntu:~/.ssh$

  1. 重新获取git的ssh地址

    需要把emb2207 这个目录改一个名称, 因为会发生重名的问题, 所以需要改名。



-> 找到自己的创库
-> 选择 "克隆/下载" 选项
-> 选择 ssh
-> 选择 复制
-> 即可得到仓库的地址
git@gitee.com:iotemb/emb2207.git
-> 在家目录下克隆代码
linux@ubuntu:~$ git clone git@gitee.com:iotemb/emb2207.git
正克隆到 'emb2207'...
The authenticity of host 'gitee.com (212.64.63.190)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,212.64.63.190' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 184, done.
remote: Counting objects: 100% (184/184), done.
remote: Compressing objects: 100% (169/169), done.
remote: Total 184 (delta 55), reused 113 (delta 14), pack-reused 0
接收对象中: 100% (184/184), 120.76 MiB | 336.00 KiB/s, 完成.
处理 delta 中: 100% (55/55), 完成.

第16章 Linux的常用服务搭建相关推荐

  1. Linux 常用服务搭建笔记(精简笔记)

    Linux 常用服务搭建笔记(精简笔记) 阅读目录 部署DNS实现解析 部署DNS主从同步 部署DNS缓存服务 部署DNS加密同步 部署DNS分离解析 部署DNS负载均衡 配置DHCP自动分配IP 配 ...

  2. 第1章 Linux系统介绍与环境搭建准备

    第1章 Linux系统介绍与环境搭建准备 本章以操作系统的介绍作开篇,首先介绍操作系统的基础概念以及操作系统的原理:然后带领读者了解Unix/Linux的诞生和发展史,以及市面上常见的Unix/Lin ...

  3. Linux之apache服务搭建以及浅析web安全

    WEB服务器的架设,在linux有一个很著名的架构叫lamp:linux+apache+mysql+php,就知道apache的分量了.   在搭建apache服务钱需要做DNS服务器 DNS的搭建h ...

  4. Linux下 FastDFS服务搭建 记录安装与配置过程

    环境准备 服务器主机名 ip 说明 tracker 192.168.1.128 负载均衡服务 storage1 192.168.1.129 存储服务 storage2 192.168.1.130 存储 ...

  5. 《Linux设备驱动开发详解》——第16章 Linux网络设备驱动一

    Linux系统对网络设备驱动定义了4各层次:网络协议接口层,网络设备接口层,提供实际功能的设备驱动功能层,网络设备与媒介层 16.1 Linux网络设备驱动的结构 (1)网络协议接口层:提供统一的数据 ...

  6. Linux运维学习:中级进阶(2)——Linux企业常用服务(SSH、DHCP、FTP、NFS、DNS)

    SSH服务 简介 SSH(Secure Shell Protocol) 是由IETF网络工作小组制定,在进行数据传输之前,SSH先对联级数据包通过加密技术进行加密处理,加密后在进行数据传输,确保了传递 ...

  7. linux中常用服务的安装

    安装环境:centos7.5 配置离线yum源 参考:https://blog.csdn.net/mayh554024289/article/details/54236336 vi /etc/yum. ...

  8. Linux下常用服务的端口号超详细整理

    来源: http://blog.csdn.net/u013943420/article/details/65938696 大家在学习计算机的时候,对于最常用的几个端口比如80端口肯定有很深的印象,但是 ...

  9. linux下FTP服务搭建(1)

    1.FTP介绍: FTP (File Transfer Protocol,文件传输协议)主要用来文件传输,尤其适用于大文件传输,提供上传下载功能 FTP官方网站:https://filezilla-p ...

最新文章

  1. 众创汇定制如何革新工业4.0?
  2. android怎么搭建人脸库,OpenCV-2.4.6-android-sdk 人脸识别demo搭建
  3. 什么是索引?为什么要建立索引?并举例说明.(以某一具体的DBMS为例)
  4. cmd 调试java_JAVA学习笔记(初级)--CMD调试
  5. 如何验证某个 string 是否为合法的 GUID ?
  6. REVERSE-PRACTICE-CthulhuOJ
  7. 2016年cypher资源_2021-2027年中国鱿鱼行业市场供需规模及未来前景分析报告
  8. 使用DQL查询数据(重点)
  9. 前端传json对象后台接收
  10. jQuery获取表单数据
  11. 摄影基础知识——曝光和测光
  12. 茜在人名可以读xi吗_茜读xi还是qian?
  13. SSD源码解读1-数据层AnnotatedDataLayer
  14. 开放api接口平台都会有appid、appkey、appsecret
  15. 机房消防报警系统及气体灭火防护的设计方法
  16. 前端性能优化:1.什么是前端性能优化
  17. php 实现抽奖接口,PHP转盘抽奖接口实例
  18. 服务器输入不显示字,搜狗输入法打字不显示怎么办 快来看看解决办法
  19. 金蝶EAS本地WebService发布
  20. 提高UG数控编程速法的15个步骤,值得收藏​

热门文章

  1. Java常用类:时间相关类
  2. [附源码]SSM计算机毕业设计班级班费缴纳及使用情况管理JAVA
  3. 常见.Net 英文专业词汇收集 [转]
  4. Nature Comm | 昆士兰大学水中心-细菌介导的新型丙烷厌氧氧化耦合硝酸盐还原过程...
  5. 小程序源码下载之外卖cps饿了么美团外卖券返利小程序+前端
  6. 图片怎么识别转换文字?这些方法可以尝试一下
  7. 商业智能BI业务分析思维:供应链分析 - 什么是牛鞭效应(一)
  8. 多看招聘广告可以拯救大学生的职业规划
  9. vmware所需要的端口
  10. Metabase学习教程:权限-1