ssh和nfs
一.ssh
1.ssh远程管理
加密的安全通信协议
1.实现字符串界面的远程登录
2.远程复制
3.sftp加密的文件传输协议
4.免密登录
2.服务器命令行的远程登录
ssh root@192.168.230.111 #默认方式,端口号是22
[root@localhost sun]# ssh root@192.168.230.111
The authenticity of host '192.168.230.111 (192.168.230.111)' can't be established.
ECDSA key fingerprint is SHA256:oiePIyR8FyQcxBuqDgav6Js8AOEeVbF2RR50B2rHTxI.
ECDSA key fingerprint is MD5:7c:a9:01:49:08:19:d8:a1:20:6a:d9:c9:05:d1:0f:85.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.230.111' (ECDSA) to the list of known hosts.
root@192.168.230.111's password:
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 6.8.0-47-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
扩展安全维护(ESM)Applications 未启用。
261 更新可以立即应用。
这些更新中有 198 个是标准安全更新。
要查看这些附加更新,请运行:apt list --upgradable
启用 ESM Apps 来获取未来的额外安全更新
请参见 https://ubuntu.com/esm 或者运行: sudo pro status
New release '24.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Thu Nov 14 14:49:20 2024 from 192.168.230.1
root@wth-virtual-machine:~#
ssh -p 10022 root@192.168.230.111
只要默认端口不是22就要-p指定端口
3.远程复制
scp远程复制命令
- 默认端口22
scp root@192.168.230.111:/opt/test.txt /opt
[root@localhost sun]# scp root@192.168.230.111:/opt/test.txt /opt
root@192.168.230.111's password:
test.txt 100% 37 23.1KB/s 00:00
[root@localhost sun]#
- 非默认端口
scp -P 10022 root@192.168.230.111:/opt/test.txt /opt
- 远程复制目录
scp -r
二. nfs
如何配置nfs共享文件
1.创建共享目录,给予权限(777)
root@wth-virtual-machine:/opt# mkdir gongxiang1 gongxiang2
root@wth-virtual-machine:/opt# ls
123 gongxiang1 gongxiang2 xy104 xy105
root@wth-virtual-machine:/opt# chmod 777 gongxiang1
root@wth-virtual-machine:/opt# chmod 777 gongxiang2
root@wth-virtual-machine:/opt# ll
总计 28
drwxr-xr-x 7 root root 4096 11月 14 14:50 ./
drwxr-xr-x 20 root root 4096 10月 28 10:04 ../
-rw-r--r-- 1 root root 0 10月 28 13:59 .000
drwxr-xr-x 2 root root 4096 10月 28 14:05 123/
drwxrwxrwx 2 root root 4096 11月 14 14:50 gongxiang1/
drwxrwxrwx 2 root root 4096 11月 14 14:50 gongxiang2/
drwxr-xr-x 6 root root 4096 10月 28 14:44 xy104/
drwxr-xr-x 3 root root 4096 10月 28 14:15 xy105/
2.安装nfs和rpcbind
root@wth-virtual-machine:~# apt -y install nfs-kernel-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
将会同时安装下列软件:
root@wth-virtual-machine:~# apt -y install rpcbind
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
3.配置
vim /etc/exports
root@wth-virtual-machine:/opt# vim /etc/exports
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/opt/gongxiang1 192.168.230.0/24(rw,sync,root_squash)
/opt/gongxiang2 192.168.230.0/24(rw,sync,root_squash)
4.重启服务
启动顺序:先启动rpcbind再启动nfs
root@wth-virtual-machine:/opt# systemctl restart rpcbind
root@wth-virtual-machine:/opt# systemctl restart nfs-kernel-server
5.服务端和客户端分别查看共享目录
服务端:showmount -e
root@wth-virtual-machine:/opt# showmount -e
Export list for wth-virtual-machine:
/opt/gongxiang2 192.168.230.0/24
/opt/gongxiang1 192.168.230.0/24
客户端:showmount -e 192.168.230.111
[root@localhost sun]# showmount -e 192.168.230.111
Export list for 192.168.230.111:
/opt/gongxiang2 192.168.230.0/24
/opt/gongxiang1 192.168.230.0/24
6.挂载使用
[root@localhost opt]# mount 192.168.230.111:/opt/gongxiang1 /opt/sun
[root@localhost sun]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 50G 3.6G 47G 8% /
devtmpfs devtmpfs 897M 0 897M 0% /dev
tmpfs tmpfs 912M 0 912M 0% /dev/shm
tmpfs tmpfs 912M 9.1M 903M 1% /run
tmpfs tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 xfs 5.0G 179M 4.9G 4% /boot
tmpfs tmpfs 183M 12K 183M 1% /run/user/42
tmpfs tmpfs 183M 0 183M 0% /run/user/0
192.168.230.111:/opt/gongxiang1 nfs4 59G 14G 43G 24% /opt/sun