您的位置:首页 > 运维架构 > Linux

linux之ssh远程登录

2016-03-08 19:05 351 查看
登录远程服务器:

Windows下使用putty绿色软件可以实现远程登录linux服务器,比较简单。着重介绍linux下ssh的远程登陆:

 

#安装sh服务器

edemon@linux:~$ sudo apt-get install ssh

#ssh远程登录,查看系统IP:

edemon@linux:~$ ifconfig

eth0      Link encap:Ethernet  HWaddr 18:67:b0:24:0a:2e

inet addr:202.118.212.121  Bcast:202.118.212.255  Mask:255.255.255.0

inet6 addr: fe80::1a67:b0ff:fe24:a2e/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:33105 errors:0 dropped:0 overruns:0 frame:0

TX packets:15454 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:15351706 (15.3 MB)  TX bytes:2159698 (2.1 MB)

lo        Link encap:Local Loopback

inet addr:127.0.0.1  Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING  MTU:65536  Metric:1

RX packets:2667 errors:0 dropped:0 overruns:0 frame:0

TX packets:2667 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:293266 (293.2 KB)  TX bytes:293266 (293.2 KB)

#使用用户jordan登录

edemon@linux:~$ ssh -l jordan 202.118.212.121

jordan@202.118.212.121's password:

Welcome to Ubuntu 15.04 (GNU/Linux 3.19.0-15-generic i686)

#

# ...

#

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by

applicable law.

$ pwd

/home/jordan

$ exit  #退出

Connection to 202.118.212.121 closed.

#尝试进入另一个地址:

edemon@linux:~$ ssh -l jordan 127.0.0.1

The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.

ECDSA key fingerprint is 3f:80:32:87:65:64:93:02:2a:98:66:39:34:6d:05:94.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '127.0.0.1' (ECDSA) to the list of known hosts.

jordan@127.0.0.1's password:

Welcome to Ubuntu 15.04 (GNU/Linux 3.19.0-15-generic i686)

#

# ...

#

Last login: Tue Mar  8 16:21:56 2016 from 202.118.212.121

$

#远程登录,使用图形界面程序:

edemon@linux:~$ ssh -X -l jordan 202.118.212.121

jordan@202.118.212.121's password:

Welcome to Ubuntu 15.04 (GNU/Linux 3.19.0-15-generic i686)

#

# 前提是开放了图形界面端口

# 修改文件 sshd_config 保证其有如下内容:

# AllowTcpForwarding yes

# X11Forwarding yes

#

$ firefox

#使用ssh密钥快速登录多台服务器:

#使用ssh生成密钥:公钥存在于服务器中,私钥是自己的。

#默认情况下生成RSA加密的密钥文件:

#密码掩码:提高密码防御恶意攻击的能力加入的干扰码。

Enter passphrase (empty for no passphrase):

Your identification has been saved in /home/edemon/.ssh/id_rsa.

Your public key has been saved in /home/edemon/.ssh/id_rsa.pub.

The key fingerprint is:

dc:ab:68:67:09:c6:fb:69:6e:af:a6:7e:f2:5e:44:67 edemon@linux

The key's randomart image is:

+---[RSA 2048]----+

|                 |

|                 |

|          . E    |

|       . o o     |

|     .  S o      |

|      +  . .     |

|     . o .o      |

|      +.O+       |

|     o+#Oo.      |

+-----------------+

#创建隐藏类文件(目录):

$ mkdir .ssh

#仅当前用户有读写权限:

$ chmod 700 .ssh

#将服务器端的.pub文件复制到客户端路径文件夹再次登录就不需要输入密码了。

edemon@linux:~$ scp .ssh/id_rsa.pub jordan@202.118.212.121:/home/jordan/.ssh/authorized_keys

jordan@202.118.212.121's password:

id_rsa.pub                                    100%  394     0.4KB/s   00:00

edemon@linux:~$ ssh -l jordan 202.118.212.121

Welcome to Ubuntu 15.04 (GNU/Linux 3.19.0-15-generic i686)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: