1

I mistakenly have source .bash_profile in the bashrc file and vice versa. Now when I tried to ssh into the machine (ec2), it will stuck at loading bash and get connection closed in a second. Is there a way I could fix it? Could I mount the disk to another ec2 instance to fix the bash files?

I tried the following solution from the other post but it doesn't work:

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

Nothing else showed up. Do you have any idea on what was going wrong?

For sanity check, if I do ssh -i "my-pem.pem"ubuntu@<server_address>.amazonaws.com, the message will be

...

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.

Update:

SFTP using FileZilla didn't work. Log:

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
3
  • I take it you cannot enter as another user, let alone as root. – rturrado Feb 26 at 12:05
  • Have a look at this other question: serverfault.com/q/94503/99881 – rturrado Feb 26 at 12:16
  • It seems sensible to think that entering via ssh but running a shell other than bash, e.g. sh or csh, should solve the problem. – rturrado Feb 26 at 12:21
0

SFTP to the instance, download the file, edit it locally, and upload the fixed file. Be careful not to clobber your existing local files by the same name, by changing to some directory other than your home directory.

2
  • I tried SFTP and it didn't work for some reason. Please see the log updated in the question. Any thoughts would be appreciated. – John M. Feb 22 at 23:56
  • @JohnM. Then yes, you should mount it to another instance as documented. – Michael Hampton Feb 23 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.