使用openssh实现免密码登录,免用户名+密码登录

有时候经常登录某台主机,会懒得输入密码,输入个用户名登录,像我这种更懒的,密码也懒得输入:

创建虚拟机:centos7

HuaiqingdeMBP:~ huaiqingcheng$ vagrant box add centos7 /Users/huaiqingcheng/Downloads/centos-7.0-x86_64.box

==> box: Box file was not detected as metadata. Adding it directly...

==> box: Adding box ‘centos7‘ (v0) for provider: 

box: Unpacking necessary files from: file:///Users/huaiqingcheng/Downloads/centos-7.0-x86_64.box

==> box: Successfully added box ‘centos7‘ (v0) for ‘virtualbox‘!


查看虚拟机

HuaiqingdeMBP:~ huaiqingcheng$ vagrant box list

centos7       (virtualbox, 0)

centos7_1     (virtualbox, 0)

centos7_2     (virtualbox, 0)

centos7_3     (virtualbox, 0)

centos7_4     (virtualbox, 0)

ubuntu_1204_1 (virtualbox, 0)

初始化虚拟机

HuaiqingdeMBP:~ huaiqingcheng$ cd ./vagrant/

HuaiqingdeMBP:vagrant huaiqingcheng$ vagrant init centos7

A `Vagrantfile` has been placed in this directory. You are now

ready to `vagrant up` your first virtual environment! Please read

the comments in the Vagrantfile as well as documentation on

`vagrantup.com` for more information on using Vagrant.

桥接并且开启虚拟机(编辑vagrantfile文件即可,网卡模式可以随意自己选择,我选择了桥接,省事)

HuaiqingdeMBP:vagrant huaiqingcheng$ vagrant up

Bringing machine ‘default‘ up with ‘virtualbox‘ provider...

==> default: Importing base box ‘centos7‘...

==> default: Matching MAC address for NAT networking...

==> default: Setting the name of the VM: vagrant_default_1490616990534_7712

==> default: Clearing any previously set forwarded ports...

==> default: Clearing any previously set network interfaces...

==> default: Available bridged network interfaces:

1) en0: Wi-Fi (AirPort)

2) en5: USB Ethernet(?)

3) en1: Thunderbolt 1

4) en2: Thunderbolt 1

5) en3: Thunderbolt 18

6) en4: Thunderbolt 20

7) p2p0

8) awdl0

9) bridge0

==> default: When choosing an interface, it is usually the one that is

==> default: being used to connect to the internet.

default: Which interface should the network bridge to? 1

==> default: Preparing network interfaces based on configuration...

default: Adapter 1: nat

default: Adapter 2: bridged

==> default: Forwarding ports...

default: 22 (guest) => 2222 (host) (adapter 1)

==> default: Booting VM...

==> default: Waiting for machine to boot. This may take a few minutes...

default: SSH address: 127.0.0.1:2222

default: SSH username: vagrant

default: SSH auth method: private key

default:

default: Vagrant insecure key detected. Vagrant will automatically replace

default: this with a newly generated keypair for better security.

default:

default: Inserting generated public key within guest...

default: Removing insecure key from the guest if it‘s present...

default: Key inserted! Disconnecting and reconnecting using new SSH key...

==> default: Machine booted and ready!

==> default: Checking for guest additions in VM...

default: The guest additions on this VM do not match the installed version of

default: VirtualBox! In most cases this is fine, but in rare cases it can

default: prevent things such as shared folders from working properly. If you see

default: shared folder errors, please make sure the guest additions within the

default: virtual machine match the version of VirtualBox you have installed on

default: your host and reload your VM.

default:

default: Guest Additions Version: 4.3.28

default: VirtualBox Version: 5.1

==> default: Configuring and enabling network interfaces...

==> default: Mounting shared folders...

default: /vagrant => /Users/huaiqingcheng/vagrant

虚机地址

inet 192.168.0.113  netmask 255.255.255.0

  • 使用openssh实现免密码登录(仅输入用户名就可以了)

    原理:使用公钥认证(私钥加密公钥解密可以进行身份验证)

    客户端生成一对密钥(public key和private key),通过将生成的公钥保存到需要认证的服务器的~/.ssh/authriedkey文件中,并且将.ssh目录的权限设置为644、authrizedkey权限设置为600即可

    ---

ssh密钥生成

HuaiqingdeMBP:vagrant huaiqingcheng$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/huaiqingcheng/.ssh/id_rsa):

/Users/huaiqingcheng/.ssh/id_rsa already exists.

Overwrite (y/n)? y

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /Users/huaiqingcheng/.ssh/id_rsa.

Your public key has been saved in /Users/huaiqingcheng/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:CCRo8ATutB5d8kXw2ApP0i2EB3yoPzWkPOnkjXHX4fw [email protected]

The key‘s randomart image is:

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

|+o+.=o..         |

|o+ *o+*  .       |

|.o++B* =+ .      |

|o.oBO=+o +       |

| +=.B++ S .      |

|. .* .     E     |

| .  .            |

|                 |

|                 |

+----[SHA256]-----+

ssh-copy-id 复制公钥(需要输入一次用户密码)

HuaiqingdeMBP:vagrant huaiqingcheng$ ssh-copy-id [email protected]

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/huaiqingcheng/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]‘s password:

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh ‘[email protected]‘"

and check to make sure that only the key(s) you wanted were added.

测试完成,免密码,需要输入用户名:

HuaiqingdeMBP:vagrant huaiqingcheng$ ssh [email protected]

Last login: Mon Mar 27 14:30:10 2017

Welcome to your Vagrant-built virtual machine.

[[email protected] ~]#

或者手动复制公钥/Users/huaiqingcheng/.ssh/id_rsa.pub到目标虚机/root/.ssh/authorized_keys文件中,~/.ssh目录的权限700,authorized_key的权限为600

  • 用openssh实现免用户名+密码登录

在~/.ssh/目录下建立config文件,编辑内容,绑定用户名和公钥

Host 192.168.0.113

HostName 192.168.0.113

User root

Port 22

IdentityFile    ~/.ssh/id_rsa

测试

HuaiqingdeMBP:vagrant huaiqingcheng$ ssh 192.168.0.113

Last login: Mon Mar 27 14:33:19 2017 from 192.168.0.101

Welcome to your Vagrant-built virtual machine.

[[email protected] ~]#

ok,拜拜

时间: 2024-08-27 19:18:22

使用openssh实现免密码登录,免用户名+密码登录的相关文章

Jquery 实现 “下次自动登录” 记住用户名密码功能

转载自:http://blog.csdn.net/aspnet_lyc/article/details/12030039?utm_source=tuicool&utm_medium=referral Jquery将用户名密码存储到cookie中 需要导入jquery.js和jquery.cookie.js <html> <head> <title>test cookie</title> <script src="Scripts/jqu

SharedPreferences实现自动登录记住用户名密码

最近Android项目需要一个自动登录功能,完成之后,特总结一下,此功能依靠SharedPreferences进行实现. SharedPreferences简介 SharedPreferences也是一种轻型的数据存储方式,它的本质是基于XML文件存储key-value键值对数据,通常用来存储一些简单的配置信息.其存储位置在/data/data/<包名>/shared_prefs目录下.SharedPreferences对象本身只能获取数据而不支持存储和修改,存储修改是通过Editor对象实现

通过Apache反向代理登录提示用户名密码错误

经典问题:Apache反向代理的session丢失问题 相关链接: http://www.iteye.com/topic/423449 http://www.cnblogs.com/taosim/articles/2920707.html 我的解决办法: Apache24\conf\extra\httpd-vhosts.conf修改如下: 加上红框内容重新启动Apache服务即可:ProxyPreserveHost On 原文地址:https://www.cnblogs.com/csh520mj

Oracle 10g 默认安装带来的用户名/密码

ORACLE数据库创建的时候,创建了一系列默认的用户和表空间 Oracle 10g 默认安装带来的用户名/密码 Username Password Description See Also CTXSYS CTXSYS The Oracle Text account Oracle Text Reference DBSNMP DBSNMP The account used by the Management Agent component of Oracle Enterprise Manager t

解决ubuntu输入正确用户密码重新跳到无法登录

http://tieba.baidu.com/p/3333869633 ubuntu登录输入用户名密码之后重新跳回登录界面Ubuntu 14.04今天学习鸟哥的私房菜使用了命令startx,通过注销重新登录,就发生了如题的情况.在登录界面输入正确的用户名密码,显示器黑屏一段时间,然后重新跳转回登录界面.重启无效. 通过在网上查找.发现了这个问题的解决方法.按照他的方法,问题最终解决. 现象:在Ubuntu登陆界面输入密码之后,黑屏一闪后,又跳转到登录界面. 原因:主目录下的.Xauthority

Linux上的ftp服务器vsftpd之配置满天飞--设置匿名用户访问(不弹出用户名密码框)以及其他用户可正常上传

一.问题背景 没事谁折腾这鬼玩意哦...还不是因为bug. 我们的应用,用户头像是存在ftp上的.之前的ftp服务器是一台windows,我们后台服务器程序收到用户上传头像的请求时,会用一个ROOT/ROOT的账户,连接ftp服务器. 获取到连接后,即进行上传. 上传:上传文件则存放在ROOT用户的home 目录(在windows上装的是server-U来充当ftp服务器,所以就是在Server-U里面配置了ROOT用户的home目录). 上传完成后,会得到一个ftp协议类型的url.范例如:

zabbix3.0 监控mysql服务免用户名密码登录的问题故障处理详细过程

1,My.cnf中用户名密码无效 在azure云上面,使用Zabbix监控mysql中,发现在/usr/local/mysql/my.cnf里面设置的默认用户名密码无效,出不来数据,而且在zabbix服务器上,使用zabbix_get也报错failed,如下 [[email protected]_serv_121_12 ~]#/usr/local/zabbix/bin/zabbix_get -s 192.168.13.13 -p10050 -kmysql.status[Uptime] /usr/

win7下怎样设置putty免用户名密码登陆

putty是一款好用的远程登录linux服务器软件,但每次输入用户名密码毕竟有些烦人,这里教你免用户名密码登陆. 工具/原料 putty 方法/步骤 去百度下载putty,小巧易用,仅有0.5M.   安装后应该会有下面的这些软件,其中putty.exe是我们需要的.   右键点击putty.exe,点击创建快捷方式.   在快捷方式上点击右键,属性.   如图,在属性窗口里的快捷方式面板中.注意目标一项,默认里面写的是你的putty的存储位置,且有引号括起来,咱们在后面加上“ -pw 密码 用

JAVA修改AD域密码_免证书认证

更改用户账户密码,必须要使用ssl方式登录到AD. 网上大部分教程使用TrustStore的方式连接, Hashtable env = new Hashtable(); System.setProperty("javax.net.ssl.trustStore", KEYSTORE); System.setProperty("javax.net.ssl.trustStorePassword", KEYSTORE_PWD); env.put(Context.INITIA