Hello I've created a user in Ubuntu and I want to connect to it using ssh using this command
ssh user@127.0.0.1 -p 2222and I got this error
ssh: connect to host 127.0.0.1 port 2222: Connection refusedI tried
ssh -vvv user@127.0.0.1 -p 2222and got
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 2222.
debug1: connect to address 127.0.0.1 port 2222: Connection refused
sssh: connect to host 127.0.0.1 port 2222: Connection refusedany help ?
Note : I am using virtualbox
I didn't install ssh, how to install it and configure it ?
39 Answers
Note, that 127.0.0.1 aka localhost is your local machine. Usually at this point you use the IP address or hostname of the remote host.
First install the ssh server and client on your target host and your local host
sudo apt-get install sshA configuration isn't necessary.
Per default SSH is listening on port 22, therefore use
ssh user@127.0.0.1 -p 22or
ssh user@127.0.0.1Or reconfigure the port for the ssh server (target host)
sudo nano /etc/ssh/sshd_configand change
Port 22to
Port 2222reload the configuration
sudo service ssh force-reloadand connect via
ssh user@127.0.0.1 -p 2222
Couple of points here
- By default Ubuntu has
sshclient (which is for out-going connection from yours to somewhere else) but nosshserver (to allow in-coming connections from other computers to yours). That means, if you wanna ssh into our computer, you need the server, which you can get withsudo apt-get install openssh-server. sshby default runs on port 22. If you try any other port, connection will be refused. So once you have ssh server, you can justssh username@localhost, and that will direct you to port 22 by default. Now, if you want to enable ssh login on port 2222, you will need to enable port forwarding. Especially since you are using virtualbox.
It looks that you don't have either:
sshddaemon running inside a VM, orport forwarding configured correctly
For 1. you need to check whether sshd server is running on a vm by for example checking with VB console that service ssh status returns that is active and running. If not run sudo service ssh start.
For 2. you can check if VB is listening on that port. You can do that by checking all open ports in LISTENING mode. sudo netstat -anp | grep -w LISTEN should include port 2222 (assuming you're using linux as a host OS).
You should have something like this in output:
tcp 0 0 0.0.0.0:**2222** 0.0.0.0:* LISTEN 1564/sshd (in this case the sshd process is listening on port 2222)
Additionally you should tell us what is your network configuration inside VB. Without it it's hard to tell whether command you're using is right.
1The following set of command will solve the problem for Ubuntu 18.04Enter the following commands in the terminal:
sudo rm /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-serverNow check with:
ssh localhostThis will work. And if you want then again install openssh with the following command:
sudo apt-get install open-ssh 2 Using below command worked for me.
$systemctl start sshd.service 1 It's all because of ssh error so I suggest you to reboot the machine and log-in again.
After log-in just open
cmd =$vi /etc/crontab and add
*/5 * * * * root service ssh restartNow for every five minutes ssh service will restart and would troubleshoot all the ssh errors.
run command
grep "^[^#;]" /etc/ssh/sshd_configand check parameter
GSSAPICleanupCredentials yes
if it is no, then update as yes and retry
The default port is 22. Using ssh xxxt@127.0.0.1 -p 22 -i ~/.ssh/xxx should work.
You should be sshing to the loopback address (127.0.1.1) for ubuntu not 127.0.0.1 IMO: