说明:使用了MacOS后发现,win系统能使用的xshell、xftp等连接服务器及其文件传输等软件均不能使用了,没有兼容的版本。所以我们刚切换到mac系统该如何去适应呢。 一、连接远程服务器 macOS中前文也说道我们使用的是ite
说明:使用了MacOS后发现,win系统能使用的xshell、xftp等连接服务器及其文件传输等软件均不能使用了,没有兼容的版本。所以我们刚切换到mac系统该如何去适应呢。
macOS中前文也说道我们使用的是iterm2进行终端控制的,所以连接远程服务器可以通过ssh来连接
缺点:每次都需要输入命令且输入密码来进行登陆,比较繁琐
疑问:有没有一种只输入一次密码就能每次简单登陆的方法呢?
#!/usr/bin/expectset timeout 30spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]expect { "(yes/no)?" {send "yes\n";exp_continue} "passWord:" {send "[lindex $argv 3]\n"}}interact# 变量说明# [lindex $argv 0]:端口号# [lindex $argv 1]:服务器用户名# [lindex $argv 2]:服务器IP地址# [lindex $argv 3]:服务器密码
# 文件名字可以随便取chmod 777 ssh_server.sh
Name:根据需求输入,通常选择标识性较强的内容便于区分,例如服务器的IP地址
Command:这里选择login Shell
Send text at start :填写格式形如A B C D E这样,每一个部分之间用空格隔开,根据自己实际情况填写,下面是对每一部分内容的解释
A代表咱们上面写的本机保存sh脚本的路径:/Users/iterm/ssh_server.shB代表服务器端口号一般远程连接端口为:22C代表服务器用户名一般为:rootD代表服务器IP:根据服务器对外暴露的公网IP填写E代表服务器密码:根据自己实际的服务器密码填写
# mac安装通过homebrewbrew install lrzsz# linux系统安装通过yumyum -y install lrzsz
wget https://raw.GitHub.com/mmastrac/iterm2-zmodem/master/iterm2-send-zmodem.sh wget Https://raw.github.com/mmastrac/iterm2-zmodem/master/iterm2-recv-zmodem.sh# 如果wget notfound brew install wget# 如果网络不佳直接去github下载# https://github.com/robberphex/iTerm2-zmodem
iterm2-send-zmodem.sh
#!/bin/bash# Author: Matt Mastracci (matthew@mastracci.com)# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script# licensed under cc-wiki with attribution required# Remainder of script public domainosascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTermif [[ $NAME = "iTerm" ]]; thenFILE=$(osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted fORM of POSIX path of thefile as Unicode text)&\"\")")elseFILE=$(osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")fiif [[ $FILE = "" ]]; thenecho Cancelled.# Send ZModem cancelecho -e \\x18\\x18\\x18\\x18\\x18sleep 1echoecho \# Cancelled transferelse# 此处需要修改# usr/local/bin/sz "$FILE" --escape --binary --bufsize 4096/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz "$FILE" --escape --binary --bufsize 4096sleep 1echoecho \# Received "$FILE"fi
iterm2-recv-zmodem.sh
#!/bin/bash# Author: Matt Mastracci (matthew@mastracci.com)# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script# licensed under cc-wiki with attribution required# Remainder of script public domainosascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTermif [[ $NAME = "iTerm" ]]; thenFILE=$(osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")elseFILE=$(osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")fiif [[ $FILE = "" ]]; thenecho Cancelled.# Send ZModem cancelecho -e \\x18\\x18\\x18\\x18\\x18sleep 1echoecho \# Cancelled transferelsecd "$FILE"# /usr/local/bin/rz --rename --escape --binary --bufsize 4096 /opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz --rename --escape --binary --bufsize 4096sleep 1echoechoecho \# Sent \-\> $FILEfi
brew list lrzsz# 以下是输出结果/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lrb/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lrx/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lrz/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lsb/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lsx/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lsz/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz/opt/homebrew/Cellar/lrzsz/0.12.20_1/share/man/ (2 files)
chmod 777 /usr/local/bin/iterm2-*
# 设置内容 Regular expression: rz waiting to receive.\*\*B0100 Action: Run Silent Coprocess Parameters: /usr/local/bin/iterm2-send-zmodem.sh Instant: checked Regular expression: \*\*B00000000000000 Action: Run Silent Coprocess Parameters: /usr/local/bin/iterm2-recv-zmodem.sh Instant: checked
注意:如果是用expect脚本登录的,无法使用lszrz。上述的脚本连接就是使用的cxpect
解决方式待更新!!!!
来源地址:https://blog.csdn.net/qq_45408390/article/details/132179290
--结束END--
本文标题: macOS(m芯片)连接服务器及其进行文件传输的各种方式的详解
本文链接: https://www.lsjlt.com/news/382930.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-13
2024-05-13
2024-05-11
2024-05-11
2024-05-10
2024-05-07
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0