2015-09-23 13:36:05 +0000 2015-09-23 13:36:05 +0000
6
6
Advertisement

SSH :connect to host localhost port 22: Connection refused

Advertisement

SSH: connect to host localhost port 22: Connection refused

Background :

私は debian で ssh を接続しようとしていました、私は kali 2.0 sana を使用しています

試した/したこと。

`apt-get install openssh-server`

openssh-server をインストールして最新版にした

サービスを問い合わせた ssh status

● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
   Active: active (running) since Wed 2015-09-23 17:20:36 IST; 36min ago
 Main PID: 1594 (sshd)
   CGroup: /system.slice/ssh.service
           └─1594 /usr/sbin/sshd -D

dpkg-reconfigure openssh-server を再設定したところ成功した

さて、接続しようとした ssh root@localhost には root@localhost のパスワードが必要なので、

vi /etc/ssh/sshd_config と root ログインを拒否するコマンドを追加した

connect to host localhost port 22: Connection refused

sshd_config は以下のようになっています。

What ports, IPs and protocols we listen for Port 22
#Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0 Protocol 2
# HostKeys for protocol version 2 HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security UsePrivilegeSeparation yes

さて、再度 ssh を root@localhost で接続しようとしたところ、iptables

が出てきました。

vim /root/firewall.rules
root@vignesh:~# iptables-save > /root/firewall.rules
root@vignesh:~# iptables -X
root@vignesh:~# iptables -t nat -F
root@vignesh:~# iptables -t nat -X
root@vignesh:~# iptables -t mangle -F
root@vignesh:~# iptables -t mangle -X
root@vignesh:~# iptables -P INPUT ACCEPT
root@vignesh:~# iptables -P FORWARD ACCEPT
root@vignesh:~# iptables -P OUTPUT ACCEPT
root@vignesh:~# iptables-save > /root/firewall.rules

iptables-saveを試してみましたが、またしてもエラーになりました。どうすれば接続できますか?

Advertisement
Advertisement

回答 (5)

14
14
14
2015-10-01 05:01:43 +0000

netstat の出力は、ポート 22 をリッスンしているプロセスがないことを示しています。

Connection refused デーモンに関する status 情報では、sshd デーモンが起動していることが示されていますが、リッスンしているポートは関連付けられていません(または関連付けられていないようです)。

さらに、コメントで言われていたように、あなたのsshd_configファイルは間違っているようです。rootログインを無効にしたいとのことなので、SSHデーモンの設定を提案します。

/etc/ssh/sshd_config ファイルを編集して、以下の内容を入れます。

Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin no
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
ClientAliveInterval 30
ClientAliveCountMax 99999

セキュリティが心配な場合は、必要なユーザのみにSSHを制限することができます。例えば、ユーザvigneshだけがSSHできるように制限したい場合は、以下のように別のディレクティブを追加します。

AllowUsers vignesh

その後、sshd サービスを再起動するだけです。これで、netstat -atpn | grep 22 を実行すると、ポート 22 がすべての人のためにリッスンしているのがわかるはずです。

3
3
3
2015-10-02 17:17:12 +0000

実際にこの行を追加したのか、それともコメントしていないのかがわかりません。ポート 22

sshd_config でポートが指定されていない場合、sshd はどのポートもリッスンしません。netstat からの出力を考えると、これが問題である可能性が高いです。

2
Advertisement
2
2
2015-10-02 04:53:58 +0000
Advertisement

まず最初に make your root account has set up with passwordもしrootがパスワードを設定していない場合はsudo passwd rootでrootの新しいパスワードを入力します。

その後、-v オプションをつけて、冗長な出力をするためにSSH接続することができます。

ssh root@localhost -v

それでも接続が拒否される場合は、ssh root@localhost -vコマンドの出力を投稿してください。

0
0
0
2017-04-27 10:04:59 +0000

手順は以下の通りです。

サーバー1のIPが192.x.x.1で、サーバー2のIPが192.x.x.2

サーバー1のIPがssh server2.com

だとします。

ssh-keygen -t rsa
cd .ssh
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.x.x.2

さて、ssh 192.x.x.2SSH :: /etc/hosts

接続エラー(/etc/hosts)が発生した場合、両方のサーバの0x6&ファイルを確認して、SERVER1とSERVER2のIPが含まれている必要があります。

私も同じエラーが出ましたが、両方のホストファイルのIPアドレスを修正することで解決しました。

0
Advertisement
0
0
2017-09-14 08:51:53 +0000
Advertisement

今日、ふと思った。この リンク によると、"Kali Linux は SSH を有効にした状態では付属していません"

Advertisement

関連する質問

6
10
3
19
2
Advertisement
Advertisement