熱門文章

顯示具有 ssh 標籤的文章。 顯示所有文章
顯示具有 ssh 標籤的文章。 顯示所有文章

2017年2月10日 星期五

免密碼 SSH Key 登入 ssh server

每次使用ssh 登入vps 都需要輸入那個又臭又長的密碼
後來找到使用公私鑰的方式來達成免密碼登入ssh


首先建立SSH Key

$ ssh-keygen -t rsa

➜  .ssh git:(master) ✗ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/***/.ssh/id_rsa): 
/Users/***/.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/QJpioneer/.ssh/id_rsa.
Your public key has been saved in /Users/QJpioneer/.ssh/id_rsa.pub.


步驟是 enter enter enter ,但因為我原本就有了所以多一個 enter y enter enter

按下enter預設會在你的家目錄底下的 .ssh 產生 id_rsa 與 id_rsa.pub
因為我原本就有ssh key 所以多一個是否覆蓋的選項(因為忘記密碼...)
怕忘記密碼所以就不設passphrase了


Mac 上可以安裝一個方便的程式來幫你設定好遠端的ssh

brew install ssh-copy-id

➜  .ssh git:(master) ✗ ssh-copy-id root@****.com
/usr/local/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/****/.ssh/id_rsa.pub"
/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/local/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@****.com's password: 

在這邊輸入一次的ssh server的密碼後之後就不用再輸入了,好方便啊


Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'root@qjpioneer.com'"
and check to make sure that only the key(s) you wanted were added.



#1組key增加
#現在請輸入 "ssh 'root@qjpioneer.com'" 登入server !!!


參考 http://ephrain.pixnet.net/blog/post/58483708-%5Blinux%5D-產生-ssh-key-來免密碼登入-ssh-server

PS. 如果你跟我一樣以前有ssh key 卻忘記密碼可以偷過這個找回來:https://help.github.com/articles/recovering-your-ssh-key-passphrase/



2017年2月7日 星期二

AWS EC2 SFTP

使用SFTP來上傳檔案

  • 需要私鑰,但必須轉成.ppk格式
  • FileZilla 
  • Host
  • 帳號密碼


Using An SSH Key

Once you have your server's SSH key, choose your preferred application and follow the steps below to connect to the server using SFTP.
FileZilla
IMPORTANT: To use FileZilla, your server private key should be in PPK format.
Follow these steps:
  • Download and install FileZilla.
  • Launch FileZilla and use the "Edit -> Settings" command to bring up FileZilla's configuration settings.
  • Within the "Connection -> SFTP" section, use the "Add keyfile" command to select the private key file for the server. FileZilla will use this private key to log in to the server.FileZilla configuration
  • Use the "File -> Site Manager -> New Site" command to bring up the FileZilla Site Manager, where you can set up a connection to your server.
  • Enter your server host name and specify bitnami as the user name.
  • Select "SFTP" as the protocol and "Ask for password" as the logon type.FileZilla configuration
  • Use the "Connect" button to connect to the server and begin an SFTP session. You might need to accept the server key, by clicking "Yes" or "OK" to proceed.

aws ec2 如何透過ssh使用phpmyadmin

使用marketplace快速安裝wordpress後,我想要使用phpmyadmi來操作MySQL 卻發現

For security reasons, this URL is only accessible using localhost (127.0.0.1) as the hostname.

不能直接用瀏覽器,必須透過以下方法:




原文

For security reasons, these applications are accessible only when using 127.0.0.1 as the hostname. To access them from a remote system, you must create an SSH tunnel that routes requests to the Apache Web server from 127.0.0.1. This implies that you must have an SSH private key and be able to connect to your server over SSH in order to access these applications remotely.

Linux And Mac OS X

To access the application using your Web browser, create an SSH tunnel, as described below.
  • Make sure you can log in to the server using SSH. Refer to the FAQ for more information on this.
  • Open a new SSH session to the server using the command below:
     ssh -N -L 8888:127.0.0.1:80 -i KEYFILE bitnami@SERVER-IP
    
    Remember to replace KEYFILE in the previous commands with the path to your private key file, and SERVER-IPwith the IP address or hostname of your virtual machine. Note that if successful, this command will create an SSH tunnel but will not display any output on the server console.
While the tunnel is active, you should be able to access the phpMyAdmin console through the secure SSH tunnel you created, by browsing to http://127.0.0.1:8888/phpmyadmin.


盡量翻譯出來.....


因為安全因素,這程式僅能允許主機(指雲端server)本地連線。如需遠端存取(就是你在用的這台client),你必須經由SSH方式向主機的apache伺服器提出請求。這表示你必須有SSH私鑰才能透過SSH連到server進而使用該程式。

Linux and Mac

使用瀏覽器存取此程式前,你必須透過SSH方式,步驟如下:

  • 確定你能夠透過SSH登入server
  • 另開視窗,使用以下command:

 ssh -N -L 8888:127.0.0.1:80 -i KEYFILE bitnami@SERVER-IP
keyfile : 你的私鑰。可以直接拖曳檔案得到私鑰路徑避免打錯
bitnami@SERVER-IP :下圖紅框即是



輸入後終端機並不會有任何的反應,請直接到瀏覽器輸入 http://127.0.0.1:8888/phpmyadmin

完成!!

參考 參考2

2016年6月17日 星期五

[Openshift]使用 rhc 下載複製(clone)程式碼

➜  ~ git:(master) ✗ rhc setup
OpenShift Client Tools (RHC) Setup Wizard

This wizard will help you upload your SSH keys, set your application namespace, and check that other
programs like Git are properly installed.

If you have your own OpenShift server, you can specify it now. Just hit enter to use the server for
OpenShift Online: openshift.redhat.com.
Enter the server hostname: |openshift.redhat.com| 

You can add more servers later using 'rhc server'.

Login to openshift.redhat.com: qjpioneer@gmail.com
Password: ********

OpenShift can create and store a token on disk which allows to you to access the server without using your
password. The key is stored in your home directory and should be kept secret.  You can delete the key at
any time by running 'rhc logout'.
Generate a token now? (yes|no) yes
Generating an authorization token for this client ... lasts about 1 month

Saving configuration to /Users/QJpioneer/.openshift/express.conf ... done

Checking for git ... found git version 2.7.4 (Apple Git-66)


Checking common problems .Enter passphrase for /Users/QJpioneer/.ssh/id_rsa: 


rhc setup

enter

email
pw
yes




今天因為修改了架設在openshift上的wordpess 的後台位置,導致我無法正常連上後台(前台都正常),回到openshift的頁面才發現,我設置的是scalable app所以無法直接安裝phpmyadmin

Installing phpMyAdmin on openshift scalable app

其中有要設置 rhc 


參考1. stackoverflow

Remove the keys: rhc sshkey-remove You can also delete them from the management console, by going to https://openshift.redhat.com/app/console/settingsOnce done, upload the public key (copy the content of your id_rsa.pub to management console) :https://openshift.redhat.com/app/console/keys/newSave it. After this try to git clone and it should work for you.

參考2. 怎樣使用git把程式碼搬到OpenShift?

我在設定 rhc setup 時搞了很久,才發現必須先按一個enter,下一行才是輸入信箱與密碼來登入openshift,在這裡失敗了好就都不知道爲什麼....

Unable to connect to the server (getaddrinfo: nodename nor servname provided, or
not known (ssh:443)). Check that you have correctly specified your OpenShift
server
'https://ssh//56c968760c1e6696010000d5@wp-qjpioneer.rhcloud.com/~/git/wp.git/'.
這部分成功後,又卡在
Checking common problems .Enter passphrase for /Users/QJpioneer/.ssh/id_rsa: 
Enter passphrase for /Users/QJpioneer/.ssh/id_rsa: 
Enter passphrase for /Users/QJpioneer/.ssh/id_rsa: 


An SSH connection could not be established to my-qjpioneer.rhcloud.com. Your SSH configuration may not be
correct, or the application may not be responding. Could not parse PKey: no start line (ArgumentError)

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
這裡我不知道要輸入什麼,找了很久(還用finder去找這個資料夾,不知怎麼看OS X系統(Mac)的隱藏資料夾而繞了一大圈,也不在裡面。

後來才想到跟git 有關,去github 也沒有....最後最後,因為我有用evernote記錄註冊的帳號密碼(當然,重要的事不會記在這),終於被我找到了

輸入後可以成功clone檔案到本機了!!
接下來才是安裝phpmyadmin的步驟啊...