这两天在公司配置Linux服务器,需要用到ssh,记录下来配置过程备忘。

环境

os:Ubuntu 12.04

1.安装
服务器端:

2.配置
2.1.修改ssh端口
默认的ssh端口是22,太扎眼,建议改成别的端口,比如3301。
修改 /etc/ssh/sshd_config文件
将其中的

# port 22
改成
port 3301
改完要重启ssh服务

3.登录
一般的登录ssh服务器的方式有两种,一种是使用密码,还有一种是使用密钥文件登录。
3.1.使用密码登录

 * Documentation:  https://help.ubuntu.com/

  System information as of Thu May 17 00:31:21 CST 2012

  System load:  0.0               Processes:           73
  Usage of /:   9.1% of 19.18GB   Users logged in:     1
  Memory usage: 14%               IP address for eth0: 192.168.56.101
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/

Last login: Thu May 17 00:22:04 2012 from 192.168.56.1
看到类似这些信息就说明登录成功了。
这种方式比较简单,但安全性稍差。
3.2.公钥-私钥登录
首先在终端执行

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

程序提示你连接一下试试,照做吧

 * Documentation:  https://help.ubuntu.com/

  System information as of Thu May 17 00:48:35 CST 2012

  System load:  0.01              Processes:           73
  Usage of /:   9.1% of 19.18GB   Users logged in:     1
  Memory usage: 15%               IP address for eth0: 192.168.56.101
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/

 * Documentation:  https://help.ubuntu.com/

  System information as of Thu May 17 00:49:08 CST 2012

  System load:  0.06              Processes:           73
  Usage of /:   9.1% of 19.18GB   Users logged in:     1
  Memory usage: 15%               IP address for eth0: 192.168.56.101
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/