0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OCI Compute インスタンスに opcユーザ以外で ssh接続する

Last updated at Posted at 2025-08-07

piyoユーザで teraterm から ssh接続できるようにします。

.sshディレクトリを作成

[root@handson-vm01 opc]# mkdir /home/piyo/.ssh
[root@handson-vm01 opc]# ls -la /home/piyo/
total 16
drwx------. 3 piyo piyo  88 Jul 31 10:14 .
drwxr-xr-x. 6 root root  58 Jul 31 10:11 ..
-rw-r--r--. 1 piyo piyo  18 May 23  2024 .bash_logout
-rw-r--r--. 1 piyo piyo 141 May 23  2024 .bash_profile
-rw-r--r--. 1 piyo piyo 376 May 23  2024 .bashrc
-rw-r--r--. 1 piyo piyo 172 Apr 12  2024 .kshrc
drwxr-xr-x. 2 root root   6 Jul 31 10:14 .ssh           ★
[root@handson-vm01 opc]#

SSHキーペアを作成。piyopiyoはパスフレーズ、piyopiyo-はコメントです。

[root@handson-vm01 opc]# ssh-keygen -t rsa -m PEM -b 2048 -N "piyopiyo" -C "piyopiyo-" -f ~/.ssh/id_rsa
Generating public/private rsa key pair.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.

公開鍵を先ほど作成した .ssh配下にコピー

[root@handson-vm01 opc]# cp /root/.ssh/id_rsa.pub /home/piyo/.ssh/authorized_keys
[root@handson-vm01 opc]# ls -la /home/piyo/.ssh/
total 4
drwxr-xr-x. 2 piyo piyo  29 Jul 31 10:28 .
drwx------. 3 piyo piyo  88 Jul 31 10:14 ..
-rw-r--r--. 1 root root 391 Jul 31 10:28 authorized_keys    ★
[root@handson-vm01 opc]#

.sshの権限を変更

[root@handson-vm01 opc]# chown -R piyo:piyo /home/piyo/.ssh/
[root@handson-vm01 opc]# ls -la /home/piyo/
total 16
drwx------. 3 piyo piyo  88 Jul 31 10:14 .
drwxr-xr-x. 6 root root  58 Jul 31 10:11 ..
-rw-r--r--. 1 piyo piyo  18 May 23  2024 .bash_logout
-rw-r--r--. 1 piyo piyo 141 May 23  2024 .bash_profile
-rw-r--r--. 1 piyo piyo 376 May 23  2024 .bashrc
-rw-r--r--. 1 piyo piyo 172 Apr 12  2024 .kshrc
drwxr-xr-x. 2 piyo piyo  29 Jul 31 10:28 .ssh      ★
[root@handson-vm01 opc]#

SSHデーモンを再起動

[root@handson-vm01 opc]# /sbin/service sshd restart
Redirecting to /bin/systemctl restart sshd.service
[root@handson-vm01 opc]#

OCI Object Storage 経由などで秘密鍵をローカルに保存し、
teraterm の SSH認証画面で保存したものを指定します。

スクリーンショット 2025-07-31 103621.png

ログインできました!

スクリーンショット 2025-07-31 103658.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?