当 ssh 进入 ec2 服务器时,如何修复无限 bash 循环(bashrc + bash_profile)?

当 ssh 进入 ec2 服务器时,如何修复无限 bash 循环(bashrc + bash_profile)?

我错误地将源文件放入文件.bash_profilebashrc,反之亦然。现在,当我尝试通过 ssh 进入机器 (ec2) 时,它会卡在加载 bash 并在一秒钟内关闭连接。有什么办法可以修复它吗?我可以将磁盘安装到另一个 ec2 实例来修复 bash 文件吗?

我尝试了另一篇文章中的以下解决方案,但它不起作用:

%  ssh -i "my-pem.pem" -t ubuntu@<server_address>.amazonaws.com "/bin/bash --noprofile --norc"
Connection to <server_address>.amazonaws.com closed.

没有出现任何其他问题。您知道出了什么问题吗?

为了进行健全性检查,如果我这样做ssh -i "my-pem.pem"ubuntu@<server_address>.amazonaws.com,则消息将是

...

28 packages can be updated.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable

New release '20.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


Last login: Mon Feb 22 23:17:41 2021 from ip
Connection to <server_address>.amazonaws.com closed.

更新:

使用 FileZilla 的 SFTP 不起作用。日志:

Status:         Connecting to <server_address>.amazonaws.com...
Status:         Using username "ubuntu". 
Status:         Connected to <server_address>.amazonaws.com
Error:          FATAL ERROR: Received unexpected end-of-file from SFTP server
Error:          Could not connect to server
Status:         Waiting to retry...
Status:         Connecting to <server_address>.compute-1.amazonaws.com...
Response:   fzSftp started, protocol_version=10
Command:    keyfile "my-perm.pem"
Command:    open "ubuntu@<server_address>.amazonaws.com" 22
Command:    Trust new Hostkey: Once
Status:         Using username "ubuntu". 
Status:         Connected to <server_address>.amazonaws.com
Error:          FATAL ERROR: Received unexpected end-of-file from SFTP server
Error:          Could not connect to server

答案1

通过 SFTP 连接到实例,下载文件,在本地编辑,然后上传修复后的文件。请注意不要更改到主目录以外的其他目录,以免破坏现有本地文件。

相关内容