Tumgik
#jp sshd(2)
mudaxolotl · 2 years
Text
just finished my current skyward sword playthrough and beat demise on my first try for the first time and also straight up sobbed during the fi cutscene at the end like i always do
1 note · View note
masaa-ma · 5 years
Text
Session ManagerでSCPとかSSH Portforwardもできる!
from https://qiita.com/taishin/items/25d91e1037d1bc80fb39?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items
Tumblr media
何の話?
以前、うちのエンジニアの人たちに、EC2に接続するときはSSHやめて、セッションマネージャーすすめてみたんですが、SSHでのターミナルだけでなく、SCPでのファイルコピーとか、インスタンス内でサービス立ち上げてアクセスするためにPortforwardとか頻繁に使うってことであまりセッションマネージャーは使っていなかったんですが・・・
こんなアナウンスが。 Session Manager launches tunneling support for SSH and SCP
これはもしや!
セットアップ
https://aws.amazon.com/jp/about-aws/whats-new/2019/07/session-manager-launches-tunneling-support-for-ssh-and-scp/
クライアント側
セッションマネージャープラグイン
1.1.22.0 が必要なのでアップデートしましょう。 https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
$ session-manager-plugin --version 1.1.23.0
SSH Config
~/.ssh/config に下記を追加します。
~/.ssh/config
# SSH over Session Manager host i-* mi-* ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
i-* はインスタンスIDを指定したとき、 mi-* はオンプレのサーバをSSMで管理している場合に使うIDです。 つまり、インスタンスIDに対してSSHアクセスしたときには、ssmでトンネル張って、その中をSSH接続するということですね。
EC2インスタンス側
SSMエージェント
2.3.672.0 以上が必要ですのでRunCommandでアップデートしてください。
EIP
SSM使うので不要です。
セキュリティグループ
もちろん外部からのSSHへのアクセス許可は不要です。
SSH Key
前述のとおり、セッションマネージャーのトンネル内でSSH接続するので、keyの付与は必要になります。 ない場合、SSHの鍵が違う場合はこんな感じ。
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
なので、EC2にsshdは必要ってことですね。
接続
普通にSSH
普通にSSHコマンドでインスタンスID指定して接続できました。
$ ssh ec2-user@i-xxxxxxxxxxxxxxx -i ~/.ssh/id_rsa ast login: Wed Jul 10 03:23:25 2019 from localhost
__| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___|
https://aws.amazon.com/amazon-linux-2/ No packages needed for security; 6 packages available Run "sudo yum update" to apply all updates. [ec2-user@ip-10-0-1-104 ~]$
おお! 普通にOSのユーザーで使えますね。
トンネル張ってるので、ログ的にはlocalhostから接続されていることになってます。
/var/log/secure
Jul 10 03:08:19 ip-10-0-1-104 sshd[4173]: Accepted publickey for ec2-user from 127.0.0.1 port 49148 ssh2: RSA SHA256:aHEcVcQEixW0amxNSFVjabsst2Jglm7KDbYr+Tyb3Zjko Jul 10 03:08:19 ip-10-0-1-104 sshd[4173]: pam_unix(sshd:session): session opened for user ec2-user by (uid=0) Jul 10 03:08:38 ip-10-0-1-104 sshd[4207]: Received disconnect from 127.0.0.1 port 49148:11: disconnected by user Jul 10 03:08:38 ip-10-0-1-104 sshd[4207]: Disconnected from 127.0.0.1 port 49148 Jul 10 03:08:38 ip-10-0-1-104 sshd[4173]: pam_unix(sshd:session): session closed for user ec2-user Jul 10 03:14:29 ip-10-0-1-104 sshd[4253]: Accepted publickey for ec2-user from 127.0.0.1 port 49216 ssh2: RSA SHA256:aHEcVcQEixW0amxNSFVjJyt2Jglm7KDbYr+Tyb3Zjko Jul 10 03:14:29 ip-10-0-1-104 sshd[4253]: pam_unix(sshd:session): session opened for user ec2-user by (uid=0) Jul 10 03:14:35 ip-10-0-1-104 sudo: ec2-user : TTY=pts/0 ; PWD=/home/ec2-user ; USER=root ; COMMAND=/bin/tail /var/log/secure
SCPしてみる
$ scp test.txt ec2-user@i-xxxxxxxxxxxxxxx:test.txt test.txt 100% 191 11.2KB/s 00:00 $ ssh ec2-user@i-xxxxxxxxxxxxxxx ls test.txt
おおお!
SSH PortForwardしてみる
$ ssh ec2-user@i-xxxxxxxxxxxxxxx sudo yum -y install httpd $ ssh ec2-user@i-xxxxxxxxxxxxxxx sudo systemctl start httpd
$ ssh -fNL 8080:localhost:80 ec2-user@i-xxxxxxxxxxxxxxx $ curl -I localhost:8080 HTTP/1.1 403 Forbidden Date: Wed, 10 Jul 2019 03:24:08 GMT Server: Apache/2.4.39 () Upgrade: h2,h2c Connection: Upgrade Last-Modified: Thu, 04 Apr 2019 18:08:00 GMT Accept-Ranges: bytes Content-Length: 3630 Content-Type: text/html; charset=UTF-8
おおおお!!!
残念ながら・・・
セッションマネージャーには出力をS3や、CloudWatch Logsに送信する機能がありますが、この接続の場合は出力されないようです。 出力はSSHになるので当然かもしれないですが・・・
まとめ
今度こそSSHするためのアクセス許可は考えなくていいことになりそう!
0 notes
mudaxolotl · 2 years
Text
continued my 3rd playthrough of skyward sword today and just kinda went off and played sky keep to the end of the game in one sitting. feeling empty inside.
1 note · View note