2017-02-24
2016-08-30
mac install .NET Core
install git
install node.js
npm install -g gulp bower
如果遇到 permission denied
要用
其他方式參考
http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo
istall donet core 需要先安裝 openssl,使用 brew 安裝 openssl
install .NET Core
執行 dotnet restore 遇到錯誤
執行以下這行,然後 dotnet restore 就能正常了
環境資訊
install node.js
npm install -g gulp bower
如果遇到 permission denied
要用
$ sudo chown -R $(whoami) ~/.npm
如果有 /usr/local/lib/node_modules 的權限錯誤$ sudo chown -R $(whoami) /usr/local/lib/node_modules
如還有 /usr/local permissions$ sudo chown -R $(whoami) /usr/local
其他方式參考
http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo
istall donet core 需要先安裝 openssl,使用 brew 安裝 openssl
$ brew update $ brew install openssl $ brew link --force openssl
install .NET Core
執行 dotnet restore 遇到錯誤
$ dotnet restoreUnhandled Exception: System.TypeInitializationException: The type initializer for 'Crypto' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Interop.CryptoInitializer.EnsureOpenSslInitialized() at Interop.CryptoInitializer..cctor() --- End of inner exception stack trace --- at Interop.Crypto..cctor() --- End of inner exception stack trace --- at Interop.Crypto.GetRandomBytes(Byte* buf, Int32 num) at System.IO.Path.GetCryptoRandomBytes(Byte* bytes, Int32 byteCount) at System.IO.Path.GetRandomFileName() at Microsoft.DotNet.InternalAbstractions.TemporaryDirectory..ctor() at Microsoft.Extensions.EnvironmentAbstractions.DirectoryWrapper.CreateTemporaryDirectory() at Microsoft.DotNet.Configurer.NuGetPackagesArchiver..ctor() at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel) at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient) at Microsoft.DotNet.Cli.Program.Main(String[] args) Abort trap: 6
執行以下這行,然後 dotnet restore 就能正常了
$ sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib 
環境資訊
$ node -vv6.5.0$ npm -v3.10.3$ dotnet --info.NET Command Line Tools (1.0.0-preview2-003121) Product Information: Version: 1.0.0-preview2-003121 Commit SHA-1 hash: 1e9d529bc5 Runtime Environment: OS Name: Mac OS X OS Version: 10.11 OS Platform: Darwin RID: osx.10.11-x64$ brew -vHomebrew 0.9.9 (git revision 8e29c; last commit 2016-08-28) Homebrew/homebrew-core (git revision 1727; last commit 2016-08-29)$ brew info opensslopenssl: stable 1.0.2h (bottled) [keg-only] SSL/TLS cryptography library https://openssl.org/ /usr/local/Cellar/openssl/1.0.2h_1 (1,691 files, 12M) Poured from bottle on 2016-08-30 at 03:15:48 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openssl.rb ==> Dependencies Build: makedepend ✘ ==> Options --universal Build a universal binary --without-test Skip build-time tests (not recommended) ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl/certs and run /usr/local/opt/openssl/bin/c_rehash This formula is keg-only, which means it was not symlinked into /usr/local. Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables: LDFLAGS: -L/usr/local/opt/openssl/lib CPPFLAGS: -I/usr/local/opt/openssl/include
2016-08-21
Mac OS 抓取螢幕截圖
1. 整個螢幕截圖:
command + shift + 3 : 取得螢幕畫面,自動儲存在桌面。
control + command + shift + 3 : 取得螢幕畫面,儲存在剪貼簿中,當你要將擷取畫面放到其它應用程式中時使用此方式。
2. 部份區域截圖:
command + shift + 4 : 拖拉擷取螢幕畫面中的區域,自動儲存在桌面。
control + command + shift + 4 : 拖拉擷取螢幕畫面中的區域,自動儲存在剪貼簿。
3. 視窗截圖:
command + shift + 4 然後按「空白鍵」切換「區域截圖」或「視窗」,自動儲存在桌面。
control + command + shift + 4 然後按「空白鍵」切換「區域截圖」或「視窗」,自動儲存在剪貼簿。
修改預設截圖檔案名稱
開啟 Terminal 輸入以下命令
defaults write com.apple.screencapture name "wei_capture(date)"
killall SystemUIServer
參考來源:
OSXDaily
修改預設截圖檔案名稱
開啟 Terminal 輸入以下命令
defaults write com.apple.screencapture name "wei_capture(date)"
killall SystemUIServer
參考來源:
OSXDaily
2015-05-12
ASP.NET MVC4 + Kendo UI - FileUpload Sample
使用 kendoui 同時上傳 model 與 檔案
Javascript:
Javascript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | [HttpPost] public ActionResult Upload([Bind(Include = "Title")]MyDataViewModel model) { if (model == null) throw new Exception("Null"); using (var transaction = _db.Database.BeginTransaction(IsolationLevel.Serializable)) { var tempFileList = new List<MyFile>(); try { model.CreateTime = DateTime.Now; model.CreateUser = Auth.CurrentId; _db.MyDataTable.Add(model); _db.SaveChanges(); for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; var fileEntity=new MyFile(file); // do save file tempFileList.Add(fileEntity); } transaction.Commit(); return new JsonResult() { Data = "Success", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } catch (Exception ex) { foreach (var file in tempFileList) { // do remove file } transaction.Rollback(); return new JsonResult() { Data = "Failure", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } } } |
2014-07-29
2013-08-15
incrementing version number (Visual Studio)
自動增加版本號
在 stackoverflow 看到一篇增加版本號的討論,其中使用 TextTransform.exe 將樣板建立成有新的版本號的 assemblyinfo.cs。裡面的步驟需要的依序建立 assemblyinfo.tt,然後在專案的建置屬性設置 prebuild。
如果每個新建專案都要加入 assemblyinfo.tt 和設定 Prebuild 又有點麻煩,所以我直接修改 Visual Studio 的 ProjectTemplates 達到每次新增專案,就已經是配置好的項目。
在 stackoverflow 看到一篇增加版本號的討論,其中使用 TextTransform.exe 將樣板建立成有新的版本號的 assemblyinfo.cs。裡面的步驟需要的依序建立 assemblyinfo.tt,然後在專案的建置屬性設置 prebuild。
如果每個新建專案都要加入 assemblyinfo.tt 和設定 Prebuild 又有點麻煩,所以我直接修改 Visual Studio 的 ProjectTemplates 達到每次新增專案,就已經是配置好的項目。
樣板路徑 是 Visual studio 安裝路徑
%ProgramFiles%\Microsoft Visual studio 9.0\Common7\Ide\ProjectTemplates
%ProgramFiles%\Microsoft Visual studio 9.0\Common7\Ide\ProjectTemplatesCache
在使用時會從 ProjectTemplatesCache 產生專案,所以可以只改 ProjectTemplatesCache
增加編譯時自動增加版本號的樣板,例如 Windows Application
D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Windows\1028\WindowsApplication
1. 覆製 assemblyinfo.cs -> assemblyinfo.tt
=====assemblyinfo.tt=====================================
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Windows.Forms" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#
int incRevision = 1;
int incBuild = 1;
try { incRevision = Convert.ToInt32(this.Host.ResolveParameterValue("","","Debug"));} catch( Exception ) { incBuild=0; }
try { incBuild = Convert.ToInt32(this.Host.ResolveParameterValue("","","Release")); } catch( Exception ) { incRevision=0; }
try {
string currentDirectory = Path.GetDirectoryName(Host.TemplateFile);
string assemblyInfo = File.ReadAllText(Path.Combine(currentDirectory,"AssemblyInfo.cs"));
Regex pattern = new Regex("AssemblyVersion\\(\"\\d+\\.\\d+\\.(?<revision>\\d+)\\.(?<build>\\d+)\"\\)");
MatchCollection matches = pattern.Matches(assemblyInfo);
revision = Convert.ToInt32(matches[0].Groups["revision"].Value) + incRevision;
build = Convert.ToInt32(matches[0].Groups["build"].Value) + incBuild;
}
catch( Exception ) { }
#>
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 組件的一般資訊是由下列的屬性集控制。
// 變更這些屬性的值即可修改組件的相關
// 資訊。
[assembly: AssemblyTitle("$projectname$")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("$registeredorganization$")]
[assembly: AssemblyProduct("$projectname$")]
[assembly: AssemblyCopyright("Copyright © $registeredorganization$ $year$")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 將 ComVisible 設定為 false 會使得這個組件中的型別
// 對 COM 元件而言為不可見。如果您需要從 COM 存取這個組件中
// 的型別,請在該型別上將 ComVisible 屬性設定為 true。
[assembly: ComVisible(false)]
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID
[assembly: Guid("$guid1$")]
// 組件的版本資訊是由下列四項值構成:
//
// 主要版本
// 次要版本
// 組建編號
// 修訂編號
//
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號
// 指定為預設值:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.<#= this.revision #>.<#= this.build #>")]
[assembly: AssemblyFileVersion("1.0.<#= this.revision #>.<#= this.build #>")]
<#+
int revision = 0;
int build = 0;
#>
3. windowsapplication.csproj 修改
<#@ output extension=".cs" #>
<#@ assembly name="System.Windows.Forms" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#
int incRevision = 1;
int incBuild = 1;
try { incRevision = Convert.ToInt32(this.Host.ResolveParameterValue("","","Debug"));} catch( Exception ) { incBuild=0; }
try { incBuild = Convert.ToInt32(this.Host.ResolveParameterValue("","","Release")); } catch( Exception ) { incRevision=0; }
try {
string currentDirectory = Path.GetDirectoryName(Host.TemplateFile);
string assemblyInfo = File.ReadAllText(Path.Combine(currentDirectory,"AssemblyInfo.cs"));
Regex pattern = new Regex("AssemblyVersion\\(\"\\d+\\.\\d+\\.(?<revision>\\d+)\\.(?<build>\\d+)\"\\)");
MatchCollection matches = pattern.Matches(assemblyInfo);
revision = Convert.ToInt32(matches[0].Groups["revision"].Value) + incRevision;
build = Convert.ToInt32(matches[0].Groups["build"].Value) + incBuild;
}
catch( Exception ) { }
#>
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 組件的一般資訊是由下列的屬性集控制。
// 變更這些屬性的值即可修改組件的相關
// 資訊。
[assembly: AssemblyTitle("$projectname$")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("$registeredorganization$")]
[assembly: AssemblyProduct("$projectname$")]
[assembly: AssemblyCopyright("Copyright © $registeredorganization$ $year$")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 將 ComVisible 設定為 false 會使得這個組件中的型別
// 對 COM 元件而言為不可見。如果您需要從 COM 存取這個組件中
// 的型別,請在該型別上將 ComVisible 屬性設定為 true。
[assembly: ComVisible(false)]
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID
[assembly: Guid("$guid1$")]
// 組件的版本資訊是由下列四項值構成:
//
// 主要版本
// 次要版本
// 組建編號
// 修訂編號
//
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號
// 指定為預設值:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.<#= this.revision #>.<#= this.build #>")]
[assembly: AssemblyFileVersion("1.0.<#= this.revision #>.<#= this.build #>")]
<#+
int revision = 0;
int build = 0;
#>
=====assemblyinfo.tt End=====================================
2. csWindowsAplication.vstemplate 加入內容 <ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.tt">AssemblyInfo.tt</ProjectItem>
<VSTemplate Version="3.0.0" Type="Project" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateContent>
<Project File="WindowsApplication.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.tt">AssemblyInfo.tt</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
<Project File="WindowsApplication.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.tt">AssemblyInfo.tt</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
</Project>
</TemplateContent>
</VSTemplate
</TemplateContent>
</VSTemplate
3.1 找到 <Compile Include="Properties\AssemblyInfo.cs"/> 用以下內容置換
<None Include="Properties\AssemblyInfo.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AssemblyInfo.cs</LastGenOutput>
</None>
<Compile Include="Properties\AssemblyInfo.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>AssemblyInfo.tt</DependentUpon>
</Compile>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AssemblyInfo.cs</LastGenOutput>
</None>
<Compile Include="Properties\AssemblyInfo.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>AssemblyInfo.tt</DependentUpon>
</Compile>
3.2 找到 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 這行下面加入以下內容,讓msbuild 時能透過樣板重建 assemblyinfo.cs
<PropertyGroup>
<PreBuildEvent>"%25CommonProgramFiles(x86)%25\microsoft shared\TextTemplating\10.0\TextTransform.exe" -a !!$(ConfigurationName)!1 "$(ProjectDir)Properties\AssemblyInfo.tt"</PreBuildEvent>
</PropertyGroup>
<PreBuildEvent>"%25CommonProgramFiles(x86)%25\microsoft shared\TextTemplating\10.0\TextTransform.exe" -a !!$(ConfigurationName)!1 "$(ProjectDir)Properties\AssemblyInfo.tt"</PreBuildEvent>
</PropertyGroup>
2013-06-01
SSH 免密碼登入
原文:http://josephj.com/article/understand-ssh-key/
一、基本流程說明
1. 私密與公開金鑰
以 SSH 登入任何主機都必需要打帳號、密碼,除了不方便、另外還增加了被竊取的風險(有些軟體如 winscp 是可儲存的)。
解決的方式就是使用金鑰產生器來產生一筆公開金鑰(Public Key)與私密金鑰(Private Key)對應做免密碼的登入。
使用者只需將公開金鑰的內容附加系統上特定的檔案中,以及在自己的環境指定好私密金鑰,系統在登入流程中即會自動對應,正確無誤即可登入,讓整個登入流程快速且安全。
解決的方式就是使用金鑰產生器來產生一筆公開金鑰(Public Key)與私密金鑰(Private Key)對應做免密碼的登入。
使用者只需將公開金鑰的內容附加系統上特定的檔案中,以及在自己的環境指定好私密金鑰,系統在登入流程中即會自動對應,正確無誤即可登入,讓整個登入流程快速且安全。
2. 金鑰種類
但是對應並沒有想像中這麼簡單,就像是木門上只能裝喇吧鎖而無法裝大鎖,不同的主機所能使用的金鑰機制也有所不同:
SSH 有 Protocol 1 及 Protocol 2 兩種[1],常見金鑰編碼機制則有 RSA1、RSA2、以及 DSA 等三種。SSH Protocol 1 使用 RSA1,SSH Protocol 2 使用 RSA或DSA。
SSH 有 Protocol 1 及 Protocol 2 兩種[1],常見金鑰編碼機制則有 RSA1、RSA2、以及 DSA 等三種。SSH Protocol 1 使用 RSA1,SSH Protocol 2 使用 RSA或DSA。
3. 保護金鑰的措施
而另外一個問題,如果有人拿到了你的私密金鑰,就相當於他可以在你的主機為所欲為。
保護的措施就是使用 Passphrase(也可以不設)、私密金鑰的密碼,每次要用時就得輸入。
保護的措施就是使用 Passphrase(也可以不設)、私密金鑰的密碼,每次要用時就得輸入。
4. Agent 機制
有 Passphrase 保護當然是安全多了,但原本想用金鑰的好處就是可以省去每次打密碼的步驟,
現在若每次又得打 Passphrase,這樣的好處就沒有了,可能還得多記一套密碼、增加打錯的可能性。
還好有 Agent 機制,他相當是你的管家、我們只要把鑰匙及 Passphrase 請他保管,在登入主機時他就會幫你解決輸入 Passphrase 的問題。
現在若每次又得打 Passphrase,這樣的好處就沒有了,可能還得多記一套密碼、增加打錯的可能性。
還好有 Agent 機制,他相當是你的管家、我們只要把鑰匙及 Passphrase 請他保管,在登入主機時他就會幫你解決輸入 Passphrase 的問題。
二、一步一步教到會
以下就只針對 Mac OSX 及 *nix 系統做介紹(若你是使用 Windows 中的 PuTTY,請先做完步驟一與二,再看這裡):
步驟 1. 產生金鑰
在 Command Line 中你可以使用 ssh-keygen 來產生各種類的金鑰,而我也會鼓勵大家一次把三種金鑰產生好,省得碰到不同系統麻煩。
a. 產生 RSA 1 金鑰
這種金鑰是給比較舊的系統,例如 FreeBSD 4 及以前的版本、是走 SSH Protocol 1 的,最好就使用 RSA 1 這種金鑰
$ ssh-keygen -t rsa1
Generating RSA keys: Key generation complete.
Enter file in which to save the key ($HOME/.ssh/identity): [按 Enter 使用預設值(建議)]
Enter passphrase: 輸入你的 Passphrase [建議要使用 passphrase,最少 12 碼]
Enter same passphrase again: 再一次輸入你的 Passphrase
Your identification has been saved in /home/username/.ssh/identity.
Your public key has been saved in /home/username/.ssh/identity.pub.
The key fingerprint is: 1c:a7:25:88:c1:fe:d2:da:a3:41:c3:a2:9f:52:59:b3 username@demo.com
b. 產生 RSA 2 金鑰
比較新的系統,如 FreeBSD 5 及之後版本或 Linux,用 RSA 2 或 DSA 這兩種金鑰
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa): [按 Enter 使用預設值(建議)]
Enter passphrase: 輸入你的 Passphrase (私密金鑰保護密碼,每次使用私密金鑰都要輸入)
Enter same passphrase again: 再一次輸入你的 Passphrase
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is: 1c:a7:25:88:c1:fe:d2:da:a3:41:c3:a2:9f:52:59:b3 username@demo.comc. 產生 DSA 金鑰
$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_dsa): [按 Enter 使用預設值(建議)]
Enter passphrase: 輸入你的 Passphrase (私密金鑰保護密碼,每次使用私密金鑰都要輸入)
Enter same passphrase again: 再一次輸入你的 Passphrase
Your identification has been saved in /home/username/.ssh/id_dsa.
Your public key has been saved in /home/username/.ssh/id_dsa.pub.
The key fingerprint is: 41:c3:a2:9f:52:59:b3:0c:cf:45:b6:cc:e8:a9:97:52 username@demo.com
經過這樣的程序,我們總共會有公私鑰共三對:RSA1 ( identity.pub / identity )、RSA2 ( id_rsa.pub / id_rsa )、及 ( id_dsa.pub / id_rsa )。
如果沒有特殊需求,你可以只用一對公私鑰,用任一個系統產生,並把這一對公私鑰給保管好即可。
步驟 2. 將公開金鑰放到主機
你現在在自己的機器上已經有了三對金鑰,接下來我們要把公開的三隻 (*.pub) 放到我們要登入的主機上。
$ scp ~/.ssh/*.pub 你欲登入的主機:~/.ssh/.
接著登入該系統,在沒設定好之前當然還是得乖乖打密碼
$ ssh 你欲登入的主機
系統預設處理放置公鑰的檔案叫做 authorized_keys,所以我們要把剛剛所傳的公鑰附加到這個檔案中:
$ cat ~/.ssh/identity.pub >> ~/.ssh/authorized_keys
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
$ chmod 711 ~/.ssh
$ chmod 644 ~/.ssh/authorized_keys
如果沒有意外,你登出再登入主機,就會看到它請你輸入 Passphrase 的訊息。
步驟 3. 設定 ssh-agent
前面所提到,每次都要打 Passphrase 就太麻煩了,所以這裡要設定管家 ssh-agent、以保管私鑰及 Passphrase。
在你每次啟動 shell 後,請照這樣的方式來做:
在你每次啟動 shell 後,請照這樣的方式來做:
a. 啟動 ssh-agent
$ eval `ssh-agent -s`
b. 將私密金鑰交給 ssh-agent 保管:ssh-add
我們將要用 ssh-add 來指定金鑰,如果你都照上面放預設的位置及相同的檔名,那就不用有任何的參數。
$ ssh-add
接著會要求你設定輸入 passphrase,如果三個都一樣,就只要打一次。
Enter passphrase for /home/username/.ssh/id_rsa:你的 Passphrase
Identity added: /home/username/.ssh/id_rsa (/home/username/.ssh/id_rsa)
Identity added: /home/username/.ssh/id_dsa (/home/username/.ssh/id_dsa)
Identity added: /home/username/.ssh/identity (username@username.com)
接著再試看看登入已經放好公鑰的主機,應該就可以不用密碼登入了!
c. 自動化流程
如果每次進 Shell 都要做 a、b 動作,可能還是太麻煩且忘記,也因此我去找了可以放在 .bash_profile 的 script ( Joseph M. Reagle Jr ),
一進入 Shell 就會把該做的動作做好,且詢問你 Passphrase:
一進入 Shell 就會把該做的動作做好,且詢問你 Passphrase:
SH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/lull
/usr/bin/ssh-add;
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn’t work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
三、公私鑰所需放的機器
我的歸納是,在本機上你必需一直保有這兩份以便後續的再製。而公鑰整理成 authorized_keys,以後有新機器需要登入時一律傳此檔案上去做附加。
而除了本機外,那些機器需要放私鑰呢?我的情況是最常用的那台開發機,因為你可能會利用他去 SSH 其它台機器。不然的話,應該減少私鑰的存放地點,以求安全。
訂閱:
文章 (Atom)