Ubuntu下ssh服务的安装

Ubuntu默认并没有安装ssh服务,如果通过ssh远程连接到Ubuntu,需要自己手动安装ssh-server。
判断是否安装ssh服务,可以通过如下命令进行:
ps -e|grep ssh
输出如下:
~$ ps -e|grep ssh
 2151 ?        00:00:00 ssh-agent

 5313 ?        00:00:00 sshd

ssh-agent表示ssh-client启动,sshd表示ssh-server启动了。

如果缺少sshd,说明ssh服务没有启动或者没有安装。
安装ssh-client命令:sudo apt-get install openssh-client

安装ssh-server命令:sudo apt-get install openssh-server

安装完成以后,先启动服务:sudo /etc/init.d/ssh start
启动后,可以通过“ps -e|grep ssh”查看是否正确启动。

ssh服务默认的端口是22,可以更改端口,使用如下命令打开ssh配置文件:
sudo nano /etc/ssh/sshd_config

# Package generated configuration file   
# See the sshd(8) manpage for details   
# What ports, IPs and protocols we listen for  
Port 22
# Package generated configuration file
# See the sshd(8) manpage for details
# What ports, IPs and protocols we listen for
修改端口号(Port)后,重启ssh服务即可生效,命令如下:
sudo /etc/init.d/ssh restart


ssh服务启动后,即可登陆,登陆命令格式为:ssh 帐号@IP地址 -p
例如:ssh test@192.168.135.249 -p


可以通过SFTP工具进行登录 

如:flashfxp 或者 FileZilla


配置ssh免密码登录

    

root@ubuntu:~/.ssh# ssh-keygen -t rsa  使用rsa加密
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
9e:32:c6:43:0c:37:92:29:be:cc:13:4a:23:c5:c4:5a root@ubuntu
The key's randomart image is:
+--[ RSA 2048]----+
| ..              |
| oE  o           |
| o+ = o          |
|.o . = .         |
|.oo   o S        |
|o+.o o . .       |
|. =   * o        |
|   . . +         |
|                 |
+-----------------+
root@ubuntu:~/.ssh# ls
id_rsa  id_rsa.pub  known_hosts    --id_rsa私钥  id_rsa.pub 公钥
root@ubuntu:~/.ssh# more id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCpxApV3r+YQztiDcS2aK0eRLZjawAT9fSXNaTRYHkG
erVRdITYqBlJdYWSAyl8MQH4t5BxXTSt1iDl86fva87MWY5jKmoMPB/11uaB9SFC/Ir4Ym9mNmbIwsVf
WxD810iEEHJO4zfaZ1Nbm+ALwvFGnwXAasT6P1vp0XTCYdtleeBWfX9RubA8NUrNm3XXRaWXX2+lba1v
D4UZV1jrPWCf2TvAa0cMiiljIa8KX5mP9LQPxbskNzr1Q6cm3XrlAgGkIfUKR2VuJnajbC+wwuFP2r/i
QqQ62BcyzgsDO5C8obR8IXlGGHfpwPNNtVaG15WTx3Rq6869eRlZCm/hKVi3 root@ubuntu
root@ubuntu:~/.ssh# cp id_rsa.pub authorized_keys    (ssh启动需要读取 用户目录/.ssh 文件中的 authorized_keys)
root@ubuntu:~/.ssh# ls 
authorized_keys  id_rsa  id_rsa.pub  known_hosts


测试是否可以直接登录

   

root@ubuntu:~/.ssh# ssh localhost
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

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

New release '14.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Mon Feb 20 16:27:36 2017 from myhost01.local
root@ubuntu:~# exit
logout
Connection to localhost closed.








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值