树莓派的Debian从8.0开始,默认关闭了SSH。打开的方式如下:

debian 开启SSH

1、修改sshd_config文件,命令为:vi /etc/ssh/sshd_config 

2、将#PasswordAuthentication no的注释去掉,并且将NO修改为YES  //我的kali中默认是yes

3、将#PermitRootLogin yes的注释去掉 //我的kali中默认去掉了注释

4、启动SSH服务,命令为:/etc/init.d/ssh start // 或者service ssh start

5、验证SSH服务状态,命令为:/etc/init.d/ssh status

6. 添加开机自启动   update-rc.d ssh enable
 

关闭则为:

自启动需要重启生效

ubuntu如何开启ssh

ssh–secure shell,提供安全的远程登录。从事嵌入式开发搭建linux开发环境中,ssh的服务的安装是其中必不可少的一步。ssh方便一个开发小组中人员登录一台服务器,从事代码的编写、编译、运行。方便代码的共享及管理。ssh是一种安全协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全。
0. SSH分客户端openssh-client和openssh-server

如果你只是想登陆别的机器的SSH只需要安装openssh-client(ubuntu有默认安装,如果没有则sudo apt-get install openssh-client),如果要使本机开放SSH服务就需要安装openssh-server。
1. 查看当前的ubuntu是否安装了ssh-server服务。默认只安装ssh-client服务。

    dpkg -l | grep ssh

这里写图片描述
2. 安装ssh-server服务

    sudo apt-get install openssh-server

这里写图片描述
再次查看安装的服务:

    dpkg -l | grep ssh

这里写图片描述
然后确认ssh-server是否启动了:

    ps -e | grep ssh

这里写图片描述
如果看到sshd那说明ssh-server已经启动了。
如果没有则可以这样启动:sudo /etc/init.d/ssh start或sudo service ssh start
配置相关:
ssh-server配置文件位于/etc/ssh/sshd_config,在这里可以定义SSH的服务端口,默认端口是22,你可以自己定义成其他端口号,如222。(或把配置文件中的”PermitRootLogin without-password”加一个”#”号,把它注释掉,再增加一句”PermitRootLogin yes”)
然后重启SSH服务:
sudo /etc/init.d/ssh stop
sudo /etc/init.d/ssh start
3. 登陆SSH(Linux)

ssh username@192.168.1.103
其中,username为192.168.1.103机器上的用户,需要输入密码。
断开连接:exit
4. 测试

(1)服务器:192.168.1.103(jackgao用户)
这里写图片描述
(2)客户端:192.168.1.104(root用户)
这里写图片描述
(3)客户端远程ssh登录服务器
这里写图片描述
(4)退出远程登录
这里写图片描述

另外,如果安装了ssh服务,windows下可以使用xshell或者putty链接这台ubuntu了(但是每次都得输入用户名和密码,即使xshell可以存储用户名和密码但是登陆速度很慢。所以可以使用公共密钥的登陆方式来提高速度和安全性。
 

Secure Shell (SSH) is a cryptographic network protocol used for a secure connection between a client and a server.

In this tutorial, we’ll show you how to enable SSH on an Ubuntu Desktop machine. Enabling SSH will allow you to remotely connect to your Ubuntu machine and securely transfer files or perform administrative tasks.

Prerequisites

Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges .

Enabling SSH on Ubuntu

The SSH server is not installed by default on Ubuntu desktop systems but it can be easily installed from the standard Ubuntu repositories.

To install and enable SSH on your Ubuntu system complete the following steps:

  1. Open your terminal either by using the Ctrl+Alt+T keyboard shortcut or by clicking on the terminal icon and install the openssh-server package by typing:
sudo apt update
sudo apt install openssh-server
  • Enter the password when prompted and enter Y to continue with the installation.
  • Once the installation is completed, the SSH service will start automatically. To verify that the installation was successful and SSH service is running type the following command which will print the SSH server status:
sudo systemctl status ssh
  • You should see something like Active: active (running) :

Press q to get back to the command line prompt.

  • Ubuntu comes with a firewall configuration tool called UFW. If the firewall is enabled on your system, make sure to open the SSH port:
sudo ufw allow ssh

Now that SSH is installed and running on your Ubuntu system you can connect to it via SSH from any remote machine. Linux and macOS systems have SSH clients installed by default. If you want to connect from a Windows machine then you can use an SSH client such as PuTTY .

Connecting to SSH Over LAN

To connect to your Ubuntu machine over LAN you only need to enter the following command:

ssh username@ip_address

Change the username with the actual user name and ip_address with the IP Address of the Ubuntu machine where you installed SSH.

If you don’t know your IP address you can easily find it using the ip command :

ip a

Debian 10 如何开机自启 Postgresql debian启动ssh_IP

As you can see from the output, the system IP address is 192.168.121.111.

Once you’ve found the IP address, login to remote machine by running the following ssh command:

ssh linuxize@192.168.121.111

When you connect through SSH for the first time, you will see a message looking something like this:

The authenticity of host '192.168.121.111 (192.168.121.111)' can't be established.
ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
Are you sure you want to continue connecting (yes/no)?

Type yes and you’ll be prompted to enter your password.

Warning: Permanently added '192.168.121.111' (ECDSA) to the list of known hosts.
linuxize@192.168.121.111's password:

Once you enter the password you will be greeted with a message similar to the one below.

Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-33-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

...

You are now logged in to your Ubuntu machine.

Connecting to SSH Over Internet

To connect to your Ubuntu machine over the Internet you will need to know your public IP Address and to configure your router to accept data on port 22 and send it to the Ubuntu machine where the SSH is running.

To determine the public IP address of the machine you’re trying to SSH to, simply visit the following URL: https://api.ipify.org .

When it comes to setting up port forwarding each router has a different way to setup port forwarding. You should consult your router documentation about how to set up port forwarding. In short, you need to enter the port number where requests will be made (Default SSH port is 22) and the private IP address you found earlier (using the ip a command) of the machine where the SSH is running.

Once you’ve found the IP address, and configured your router you can log in by typing:

ssh username@public_ip_address

If you are exposing your machine to the Internet it is a good idea to implement some security measures. The most basic one is to configure your router to accept SSH traffic on a non-standard port and to forward it to port 22 on the machine running the SSH service.

You can also set up an SSH key-based authentication and connect to your Ubuntu machine without entering a password.

Disabling SSH on Ubuntu

If for some reason you want to disable SSH on your Ubuntu machine you can simply stop the SSH service by running:

sudo systemctl stop ssh

To start it again run:

sudo systemctl start ssh

To disable the SSH service to start during system boot run:

sudo systemctl disable ssh

To enable it again type:

sudo systemctl enable ssh