Ubuntu系统使用SecureCRT进行远程命令执行的步骤
SecureCRT通过SSH协议实现远程连接,因此需先确认Ubuntu服务器已安装并启动SSH服务。
sudo apt update && sudo apt install openssh-server -y
sudo systemctl start ssh # 启动SSH服务
sudo systemctl enable ssh # 设置开机自启
sudo systemctl status ssh,若显示“active (running)”则表示服务正常运行。Ctrl+N),弹出“新建会话”窗口。192.168.1.100);ubuntu、root等)。id_rsa);ls查看当前目录、cd切换目录、reboot重启服务器等),按回车键执行。执行结果会实时显示在终端窗口中。ls -l;mkdir test_folder;uptime;sudo reboot(需输入当前用户密码)。若需批量或重复执行命令,可使用SecureCRT支持的脚本语言(如VBScript、Python)编写自动化脚本。
ls命令):' 定义变量
Dim strUsername, strPassword, strHost
strUsername = "your_username" ' 替换为Ubuntu用户名
strPassword = "your_password" ' 替换为Ubuntu密码
strHost = "192.168.1.100" ' 替换为Ubuntu服务器IP
' 连接远程主机
crt.Session.Connect "/SSH2 /AUTH PASSWORD /USER:" & strUsername & " /PASSWORD:" & strPassword & " " & strHost
' 等待登录完成(等待命令提示符,如$或#)
crt.Screen.WaitForString "$"
' 发送命令并等待执行完成
crt.Screen.Send "ls -l" & vbCr
crt.Screen.WaitForString "$"
' 获取命令输出(可选)
Dim output
output = crt.Screen.ReadString("$")
crt.Popup output ' 弹出消息框显示输出
' 断开连接
crt.Session.Disconnect
将脚本保存为.vbs文件(如remote_command.vbs),在SecureCRT中点击“工具”→“脚本”→“运行”,选择该脚本即可执行。ufw)限制SSH端口(22)的访问IP,仅允许可信IP连接;