---
title: "Ubuntu 服务器上 SSH Server 的安装和启动"
author: "cms163"
date: "2014-04-25T11:26:38Z"
tags: []
categories: ["操作系统"]
slug: "ubuntu-ssh-server"
draft: false
lastmod: "2014-04-25T11:39:09Z"
id: 2054481
url: "https://cms163.iteye.com/blog/2054481"
---

Ubuntu 下安装 OpenSSH Server 是无比轻松的一件事情，需要的命令只有一条：

sudo apt-get install openssh-server

随后，Ubuntu 会自动下载并安装 openssh server，并一并解决所有的依赖关系。当您完成这一操作后，您可以找另一台计算机，然后使用一个 SSH 客户端软件（强烈推荐 PuTTy），输入您服务器的 IP 地址。如果一切正常的话，等一会儿就可以连接上了。并且使用现有的用户名和密码应该就可以登录了。

在Ubuntu终端使用命令测试：

ssh localhost

如果出现以下错误，则很可能是因为还没有安装ssh-server：

ssh: connect to host localhost port 22: Connection refused

 

**一、安装SSH SERVER（两种方法）**

 

**方法1.在线安装：**

sudo apt-get update

sudo apt-get install openssh-server openssh-client

 

**方法2.离线安装：**

需先下载安装文件 openssh-server\_5.5p1-4ubuntu4\_i386.deb    
 sudo dpkg -i openssh-server\_5.5p1-4ubuntu4\_i386.deb

 

 

**二、确认SSH SERVER 服务是否安装好**

ps -e | grep sshd  
  450 ?        00:00:00 sshd

如果看到sshd那说明ssh-server已经启动了。  
如果只有ssh-agent说明ssh-server还没有启动，需要执行命令启动ssh服务：  
/etc/init.d/ssh start；  
注：在ubuntu-12.04-server-i386.iso安装中只显示sshd这一项：

 

 

 

**三、扩展配置**  
SSH默认服务端口为22，用户可以自已定义成其他端口，如222，需要修改的配置文件为：  
/etc/ssh/sshd\_config  
把里面的Port参数修改成222即可  
然后重启SSH服务：  
sudo/etc/init.d/ssh restart

 

 

 

 

**启动SSH-Server**

sudo /etc/init.d/ssh start

重启ssh服务  
sudo /etc/init.d/ssh restart

 

然后使用以下方式登陆SSH：  
ssh [root](mailto:root@192.168.0.100)[@192.168.0.100]()  root为192.168.0.100机器上的用户，需要输入密码。

断开连接：exit