Last active
April 25, 2024 08:27
-
-
Save roommen/18cd78d07b0fbc962de4e79c1d468f92 to your computer and use it in GitHub Desktop.
OpenSSH Update Script - Amazon Linux 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo yum install gcc -y | |
sudo yum install openssl-devel -y | |
sudo yum install zlib-devel -y | |
sudo yum install mlocate -y | |
sudo yum install autoconf -y | |
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.1p1.tar.gz | |
tar zxvf openssh-9.1p1.tar.gz | |
cd openssh-9.1p1 && ./configure && make && sudo make install |
If your colleague also decided to follow these instructions on your day-off, and now finds themselves in a situation where the OpenSSH server is almost inaccessible anymore for new connections (e.g. ssh your-server-ip
returns with error "kex_exhcnage_identification: read: Connection reset by peer"), follow my instructions to restore everything back.
Assuming you (or your coworker) still have an open SSH connection and can run commands in the shell:
- Set a secure password for the root user using
sudo passwd
(you can use tools like pwgen to generate a strong password). - Log into the AWS console, navigate to your EC2 instance, select it, then go to Actions → Monitor and troubleshoot → EC2 serial console → Connect
- Press Enter a few times in the large black rectangle, and you'll get a login prompt. Type root, press Enter, and then enter the password generated in step 1
- Stop the SSH server and terminate all connections by running
systemctl stop sshd; killall sshd
- Navigate to the openssh server source code directory, most likely it would be
cd /home/ec2-user/openssh-9.1p1
- Run
make uninstall
to clean up all the files installed by the previous "make install" command (please avoid doing this on any non-personal machines in the future). - After step 6, you'll no longer have SSH client & SSH server on your system, even though the system package manager still thinks OpenSSH is installed. Reinstall the SSH-related packages to restore everything:
yum reinstall openssh openssh-server openssh-client
- Finally, start the SSH server again by running
systemctl start sshd
, and check if you can connect to the server from the server itself byssh localhost
.
P.S. If upgrading is necessary to make npm work (due to the unsupported option "accept-now"), you can use this workaround by setting an environment variable: GIT_SSH_COMMAND=ssh npm i ...
(Source)
I am use centOS 7.6, it should like this
./configure --with-ssl-dir=/usr/local/openssl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After a period of research, here are some conclusions(which may be useful to you).
Checking
configure
help docAs you can see, here is a param
--with-ssl-dir=PATH
that can be used for specify openssl path.Dive into
openssl11
The path
/usr/include/openssl
is the path that you should fill into above.Conclusion
Run before:
sudo yum install -y gcc openssl11 openssl11-devel zlib-devel mlocate autoconf
Try:
./configure --with-ssl-dir=/usr/include/openssl
BTW, The above method has been verified to work on a brand new AL2 system.