Running ssh on Amazon EC2 instance on port other than 22

前端 未结 3 1623
孤城傲影
孤城傲影 2020-12-14 20:33

I am not able to access Amazon EC2 instance via ssh as i am behind a firewall. So, i thought of running ssh on port other than 22, like 80 or 443.

I tried starting A

3条回答
  •  既然无缘
    2020-12-14 21:13

    Here is what I came up with to run sshd on 443 and 22 having rhel8 on ec2

    1. make sure your security groups allow connection from your network/ip to the desired ports (in my case 22 and 443)
    tcp 443 1.2.3.4/32 #allow access to 443 from IP 1.2.3.4
    tcp 22 1.2.3.4/32 #allow access to 22 from IP 1.2.3.4
    
    1. Login to the EC2 and
    #install semanage with
    sudo yum install -y policycoreutils-python-utils
    #delete 443 from http ports
    sudo semanage port -d -t http_port_t -p tcp 443
    #add 443 to ssh ports
    sudo semanage port -m -t ssh_port_t -p tcp 443
    
    1. Edit /etc/ssh/sshd_config
    Port 22
    Port 443
    
    1. Restart sshd
    sudo service sshd restart
    

提交回复
热议问题