Ubuntu14.04使用有一段时间了,今天图方便,想在工作机上使用SecureCRT远程登陆笔记本.

要ssh远程,首先需要安装ssh服务:

1
xxx@ThinkPad-X100e:~$sudo apt-get install ssh

然后启用root账号,给root账号设置密码:

1
xxx@ThinkPad-X100e:~$sudo passwd root

ssh等一般默认就设置就可以了,如果需要个性化端口等设置,google一把设置方法.安装完重启系统或者使用命令启动ssh服务:

1
xxx@ThinkPad-X100e:~$sudo service ssh start

接下来使用SecureCRT登陆,居然提示认证失败,各种设置密码,还是同样提示.google一把说Ubuntu14.04默认做了限制,需要修改/etc/ssh/sshd_config这个文件.

/etc/ssh/sshd_config原始内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Package generated configuration file
See the sshd_config(5) manpage for details

# 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
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
# Don’t read the user’s ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
For this to work you will also need host keys in /etc/ssh_known_hosts

RhostsRSAAuthentication no
similar for protocol version 2

HostbasedAuthentication no
Uncomment if you don’t trust ~/.ssh/known_hosts for RhostsRSAAuthentication

#IgnoreUserKnownHosts yes

将以上登陆验证部分内容修改为:

1
2
3
4
5
6
7
# Authentication:
LoginGraceTime 120
#将PermitRootLogin without-password注销掉,不允许无密码登陆
#PermitRootLogin without-password
#PermitRootLogin yes,允许root登陆,默认是没有的,我们加上这行
PermitRootLogin yes
StrictModes yes

保存退出,再次重启sshd服务,登陆ok.