要在Ubuntu系统中配置sshpass以简化登录过程,请按照以下步骤操作:
打开终端(Terminal)。
首先确保系统已更新。在终端中输入以下命令并按回车键:
sudo apt-get update安装sshpass。在终端中输入以下命令并按回车键:sudo apt-get install sshpass创建一个包含目标服务器登录信息的文本文件。例如,创建一个名为“servers.txt”的文件,其中包含以下内容:user1@server1.example.comuser2@server2.example.com将此文件保存在一个安全的位置,例如/home/your_username/servers.txt。
#!/bin/bashinput="/home/your_username/servers.txt"while IFS= read -r linedo user=$(echo $line | cut -d'@' -f1) server=$(echo $line | cut -d'@' -f2) echo "Logging in to $server as $user..." sshpass -p 'your_password' ssh -o StrictHostKeyChecking=no $user@$serverdone < "$input"将your_username替换为你的用户名,将your_password替换为你的密码。保存文件并使其可执行:
chmod +x login_servers.sh运行脚本以自动登录到服务器列表中的所有服务器:./login_servers.sh现在,你应该能够使用sshpass自动登录到服务器列表中的所有服务器。请注意,将密码存储在脚本或文本文件中可能会导致安全风险。因此,请确保在安全的环境中使用此方法,并定期更改密码。


