Se cambio la mia porta SSH da 22 a 23453, non riesco più a collegarmi.
Più in dettaglio, sto usando un'istanza Red Hat EC2 su Amazon Web Services. Questa è la seconda modifica che ho su una nuova installazione (la prima modifica è stata quella di aggiungere un utente non root).
Posso ssh bene usando Git Bash e un file .ssh / config locale, modifico la riga in / etc / ssh / sshd_config che attualmente dice
#Port 23453
dire
Port 23453
quindi riavviare sshd con
sudo service sshd restart
Aggiungo quindi una riga "Porta 23453" il mio file .ssh / config
Host foo
Hostname my-ec2-public-DNS
Port 23453
IdentityFile my ssl key
Se apro un'altra shell Git Bash (senza chiudere la mia connessione esistente) e provo a ssh nella mia istanza (con ssh foo) vedo il seguente errore:
ssh: connect to host my-ec2-public-DNS port 23453: Bad file number
Il gruppo di sicurezza collegato a questa istanza ha due voci, entrambe TCP
22 (SSH) 0.0.0.0/0
23453 0.0.0.0/0
La mia ipotesi migliore è che la porta sia ancora bloccata dal mio firewall.
L'output di sudo iptables -Lè il seguente
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Il che mi sembra abbastanza aperto.
AGGIORNARE
Dopo aver aggiunto una regola iptables
iptables -A INPUT -p tcp --dport 23453 -j ACCEPT
e riprovare, ancora nessuna fortuna.
Uscita di iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- anywhere anywhere tcp dpt:23453
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Che sembra sufficientemente aperto. Non sono del tutto sicuro di come cercare pacchetti in arrivo o attività sulla porta. Ma l'output di netstat -ntlp(come root)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:56137 0.0.0.0:* LISTEN 948/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 930/rpcbind
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1012/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1224/master
tcp 0 0 0.0.0.0:23453 0.0.0.0:* LISTEN 32638/sshd
tcp 0 0 :::36139 :::* LISTEN 948/rpc.statd
tcp 0 0 :::111 :::* LISTEN 930/rpcbind
tcp 0 0 ::1:631 :::* LISTEN 1012/cupsd
tcp 0 0 :::23453 :::* LISTEN 32638/sshd
Il che mi sembra mostrare sshd il 23453.
Ho ricontrollato che l'istanza ha la porta aperta nel gruppo di sicurezza (Porta: 23453, Protocollo: tcp, Fonte: 0.0.0.0/0)
Cos'altro può causare la mancata connessione tramite SSH?
Saluti
POSTMORTEM
Ora posso collegarmi. Era una regola mancante in iptables. L'output di iptables -Lnow è simile al seguente:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:23453 state NEW
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
iptables -L(funziona ssh) e il secondoiptables -L(ssh è bloccato). Guarda l'ordine delle regole nella catena INPUT (le 6 righe sotto il primo "target"), vengono lette dall'alto verso il basso, quindi nella seconda serie di regole, "REJECT all" viene colpito prima di "ACCEPT tcp DPT: 23453" . La terza serie di regole ha la voce ACCEPT sopra, e quindi prima, la voce REJECT.