我有以下问题:
我有我的网络驱动器在我的家庭网络,我想通过sshfs挂载。在我的本地网络中,我不需要太在意加密,可以使用arcfour密码。我的ssh内部端口是A。出于技术原因,我可以通过ssh在端口B上连接外部网络,这与A不一样。在我的家庭网络中,我也无法从外部连接到那个端口。现在,从外部安装,我当然会依赖其他加密。
我想要构建一个systemd-service,它可以很好地处理这种情况,在端口A上使用arcfour,在使用ID X的网络中,并在所有其他情况下通过端口B连接到另一个密码。对于编写自己的服务,我仍然有些陌生,也找不到合适的条件在这里工作。
有人能帮我解决这个问题吗?
发布于 2019-10-28 16:53:55
我建议您运行两个操作:一个在登录时运行(用于挂载),另一个在注销时运行(卸载)。示例服务文件:
[Unit]
Description=mount with sshfs
[Service]
Type=simple
ExecStart=/path/to/login_script.sh
#This makes the service stay active while logged in and
# makes sure ExecStop is only executed at logout
RemainAfterExit=yes
ExecStop=/path/to/logout_script.sh
[Install]
#opens with first login and ends with last logout - multiple ssh sessions are OK
WantedBy=default.target编写用于登录和注销的脚本。我会通过SSID检查一下,看看我们是否在家。看看什么适合你。
#!/bin/bash
#login script
if [[ "$( nmlci | grep 'home_network_name' )" != "" ] ; then
#we're at home
sshfs <mount with home options>
else
#we're out
sshfs <mount with outside options>
fi注销后,您想要卸载
#!/bin/bash
#logout script
fusermount -u /path/to/mount/point要激活服务,将其放入例如~/.cofig/systemd/user/autosshfs.service并运行systemctl --user enable autosshfs.service。它应该在下一次登录时起作用。
https://unix.stackexchange.com/questions/549143
复制相似问题