59.111.94.46:6379> config set dbfilename authorized_keys OK
并将准备好的公钥内容写入持久化文件
59.111.94.46:6379>set xxx "\n\n\nssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWuati70x2tsLBJ6FxDgK5NnRhUiIYMHEL9Nt0cwtOvlc8it7Ta9uSzQX6RV3hpF0Txg8/ARZaq75JyzN+1jsNh35mR49YWJloU8FbiI28IjdKAVvCOcAd/WWsPWrRIJPG38Z8Bu2xXBsNCmMwOtPd6VL4k9j6xmeA52PLe4wBJHZbGkPrbTxd7TTtvuWWmbx0dzvXBYCIalhVOJ7u5471tMBoCFGCYh5V8lzS0c4Hm3tf5SuQ8G3vWP8fLE6iUGen9rqBu+QNSxlYJSwz+O5T/ErFTFPZI3USQM7th1r6iY/Z8O7AzZlhXzPCHKcd/+8mzcEJ1JFU8m9gXgF6JwER ubuntu@ubuntu-xenial\n\n\n" OK
保存
59.111.94.46:6379> save OK 59.111.94.46:6379>
远程登陆
ubuntu@ubuntu-xenial:~$ ssh root@59.111.94.46 The authenticity of host '59.111.94.46 (59.111.94.46)' can't be established. ECDSA key fingerprint is SHA256:ST9pjK2KmcxY+e7zJmu+ePtan7VbCx7rMmPpMEutc68. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '59.111.94.46' (ECDSA) to the list of known hosts. Last login: Tue Dec 2620:17:392017 from 115.193.160.107 [root@centos ~]#
nmap -sT -p 6379 10.111.0.0/16 | grep --color -B5 open
Nmap scan report for 10.111.0.185 Host is up (0.049s latency). PORT STATE SERVICE 6379/tcp open unknown -- 6379/tcp filtered unknown
Nmap scan report for 10.111.17.100 Host is up (0.049s latency). PORT STATE SERVICE 6379/tcp open unknown
连接测试
fangwenjun@instance-1:~$ redis-cli -h 10.111.17.100 10.111.17.100:6379> ping (error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication passwordis requested to clients. In this mode connections are only accepted from the loopback interface. If you want toconnectfromexternal computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no'from the loopback interface by connecting to Redis from the same host the serveris running, however MAKE SURE Redis isnot publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode optionto'no', andthen restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no'option. 4) Setup a bind address or an authentication password. NOTE: You only need todo one of the above things inorderfor the servertostart accepting connections from the outside. 10.111.17.100:6379>