一、准备工作:安装并启动SecureCRT 确保已从VanDyke Software官网下载并安装SecureCRT(支持Windows、Mac等平台)。安装完成后,打开软件进入主界面,准备配置Linux连接。
二、建立SSH连接(基础步骤)
192.168.1.100
或example.com
);root
或普通用户ubuntu
)。id_rsa.pub
、私钥id_rsa
),在「New Session Wizard」中选择「PublicKey」,点击「Properties」→「SSH2」→「Authentication」,将私钥文件路径添加至「Private key file」,并勾选「Priority use public key authentication」,登录时无需输入密码。三、执行Linux命令
$
或#
开头,#
表示root用户)。直接输入命令并按「Enter」键执行,例如:
ls -l
:列出当前目录下的文件及权限、所有者等信息;cd /home
:切换到/home
目录;pwd
:显示当前所在目录的绝对路径;uname -a
:查看Linux系统内核版本、主机名等信息。cp file1.txt file2.txt
(复制文件)、mv old_name new_name
(重命名文件)、rm -rf dir/
(删除目录及其内容,慎用);ps aux | grep nginx
(查看nginx进程)、top
(实时查看系统资源占用)、kill -9 PID
(强制终止指定PID的进程);chmod 755 script.sh
(给脚本添加可执行权限)、chown user:group file.txt
(修改文件所有者)。四、进阶功能:脚本与自动化
~/.securecrt/scripts/
)。.scr
格式),SecureCRT会自动执行录制的操作。send
发送命令、expect
等待回显),示例如下:#!/usr/bin/env tcl
proc execute_command {command} {
puts "Executing: $command"
send "$command\r"
expect "*\r\n"
puts "Output: $expect_out(buffer)"
}
spawn ssh user@example.com
expect "assword:"
send "your_password\r"
execute_command "ls -l /tmp"
execute_command "df -h"
send "exit\r"
expect eof
linux_tasks.tcl
,点击「Script」→「Run Script」选择该文件,即可自动执行脚本中的命令。五、注意事项
rm -rf
、chmod 777
)前,确认命令作用对象,防止误操作导致数据丢失。